Hello guys, if you are learning to code and programming or preparing for a programming job interview and looking for some practice material then you have come to the right place. In this article, I am going to share some of the most common Java coding and programming problems for beginners. These are the problems, I have solved myself to learn to program and develop a coding sense. These programs are very simple but will teach you a lot about computer science, problem-solving, data structure, algorithms, programming languages, control structure and in general how to think of a solution and then translate into code. I call that coding sense and that's probably the most important thing for a programmer. It doesn't come overnight and it slowly develops when you utilize that part of your brain by solving coding problems.

I have listed the problems in no particular order and that's why you can solve in any order you want. I generally pick a problem which is the easiest one to solve like checking if a number is even or odd, or calculating factorial, or checking if a given number is a palindrome.

Once you solve one problem, you can move to another but try as much possible yourself before looking at the solution. Yes, I have also linked to the solution wherever possible. For some problems, I have not linked to the solution, which you can find by doing a quick Google search.

While most of the problems don't expect much but you should be familiar with the programming languages you are trying to learn like how to write for loop, and how to create a function, how to use if-else and other conditional operators, etc. Actually, if you don't know, you will also learn when you try to solve these problems but then you need to check the solution first.

Some problems also require you to be familiar with essential data structures like an array, linked list, binary tree, stack, queue, binary search tree, graph, etc. If you are not familiar or need to revise those concepts then you can also check out

I have given a solution in Java programming language because that's my favorite and strongest skill but you are free to solve these coding problems in any programming language of your choice like Python, JavaScript, Ruby, or even Golang.

##

Without wasting any more of your time, here is my list of 50+ Coding and Programming Problems for Java programmers.

1. For a given array of integers (positive and negative) find the largest sum of a contiguous sequence

2. Algorithm: Implement a queue using 2 stacks

3. Algorithm: Integer division without the division operator (/)

4. Algorithm: All permutations of a set

5. Algorithm: All combinations of a set

6. Given an array of n integers(consider +ve and also -ve), find a subarray such that sum of that array s maximum.

7. Tortoise and hare algorithm

8. Given two strings .. you need to tell whether they are a permutation of each other.

9. Given a string. You need to print the first non-repeating char.

10. Given two sorted lists, combine them into one sorted list.

11. Insert a node in a doubly-linked list.

12. You are given an integer array of size n containing elements in the range 0 to n-1. Now count the frequency of all elements.

13. Given an array where every element occurs three times, except one element which occurs only once. Find the element that occurs once.

Input: arr[] = {12, 1, 12, 3, 12, 1, 1, 2, 3, 3} Output: 2

14. Given a positive integer n, count the total number of set bits in a binary representation of all numbers from 1 to n.

Examples:

Input: n = 3

Output: 4

Input: n = 6

Output: 9

15. Write a function Add() that returns the sum of two integers. The function should not use any of the arithmetic operators (+, ++, –, -, .. etc). (solution)

16. Write a Java program to find the smallest of three integers, without using any of the comparison operators.

17. Fibonacci Series (solution)

18. Armstrong Numbers (solution)

19. Check if a number is Even or Odd (solution)

20. Java Program to find GCD of two numbers (solution)

21. Check if a number is a palindrome or not (solution)

22. Check if String is palindrome or not

23. Java Program to calculate Simple interest (solution)

24. Java Program to check a leap Year (solution)

25. Code algorithm for Bubble Sort in Java (solution)

26. Code algorithm for Insertion sort

27. Algorithm for QuickSort (solution)

28. Algorithm for Selection Sort

29. Algorithm for Merge Sort (solution)

30. Algorithm for Heap Sort

31. Java Program to count vowels and consonants in a String (solution)

32. How to reverse String in Java (solution)

33. Java Program to reverse a number (solution)

34. Factorial (solution)

You need to write a program to check if the given number is prime or not. If the given number is prime then return true otherwise return false. A prime number is a number that is not divisible by any number except 1 and itself.

36. Area of a triangle (solution)

37. middle elements of the linked list (solution)

38. Count occurrences of characters in String (solution)

39. Check if a number is positive or negative (solution)

40. Swap two numbers without using temp variable

41. How to check if two Strings are Anagram (solution)

42. Check if a number is the power of Two or not (solution)

43. How to check if LinkedList contains loops or cycles? (solution)

44. Program to find the sum of digits in a number (solution)

hint - this is a common Java coding problem, you can remove duplicates from array creating a new array of unique elements. To find unique elements use a set and copy array elements there. set will not allow duplicates so you will have an array of unique elements.

46. Find whether a given number is a power of 4 or not

47. Compute the minimum or maximum of two integers without branching

48. Given an unsigned integer, swap all odd bits with even bits. For example, if the given number is 23 (00010111), it should be converted to 43 (00101011). Every even position bit is swapped with the adjacent bit on the right side (even position bits are highlighted in the binary representation of 23), and every odd position bit is swapped with an adjacent on the left side.

49. Given an array in which all numbers except two are repeated once. (i.e. we have 2n+2 numbers and n numbers are occurring twice and remaining two have occurred once). Find those two numbers in the most efficient way.

50. Write an Efficient C Program to Reverse Bits of a Number

51. Count number of set bits in a number (solution)

52. Given two signed integers, write a function that returns true if the signs of given integers are different, otherwise false. For example, the function should return true -1 and +100 and should return false for -100 and -200. The function should not use any of the arithmetic operators.

53. LRU cache implementation.

Grokking the Coding Interview: Patterns for Coding Questions

Data Structure and Algorithms Analysis - Job Interview

Data Structures and Algorithms: Deep Dive Using Java

Algorithms and Data Structures - Part 1 and 2

From 0 to 1: Data Structures & Algorithms in Java

Cracking the Coding Interview - 189 Questions and Solutions

I have listed the problems in no particular order and that's why you can solve in any order you want. I generally pick a problem which is the easiest one to solve like checking if a number is even or odd, or calculating factorial, or checking if a given number is a palindrome.

Once you solve one problem, you can move to another but try as much possible yourself before looking at the solution. Yes, I have also linked to the solution wherever possible. For some problems, I have not linked to the solution, which you can find by doing a quick Google search.

While most of the problems don't expect much but you should be familiar with the programming languages you are trying to learn like how to write for loop, and how to create a function, how to use if-else and other conditional operators, etc. Actually, if you don't know, you will also learn when you try to solve these problems but then you need to check the solution first.

Some problems also require you to be familiar with essential data structures like an array, linked list, binary tree, stack, queue, binary search tree, graph, etc. If you are not familiar or need to revise those concepts then you can also check out

**Data Structures and Algorithms: Deep Dive Using Java**course on Udemy to learn those fundamental data structures first.I have given a solution in Java programming language because that's my favorite and strongest skill but you are free to solve these coding problems in any programming language of your choice like Python, JavaScript, Ruby, or even Golang.

##
__50+ Coding and Programming Problems for Java Programmers__

Without wasting any more of your time, here is my list of 50+ Coding and Programming Problems for Java programmers.1. For a given array of integers (positive and negative) find the largest sum of a contiguous sequence

2. Algorithm: Implement a queue using 2 stacks

3. Algorithm: Integer division without the division operator (/)

4. Algorithm: All permutations of a set

5. Algorithm: All combinations of a set

6. Given an array of n integers(consider +ve and also -ve), find a subarray such that sum of that array s maximum.

7. Tortoise and hare algorithm

8. Given two strings .. you need to tell whether they are a permutation of each other.

9. Given a string. You need to print the first non-repeating char.

10. Given two sorted lists, combine them into one sorted list.

11. Insert a node in a doubly-linked list.

12. You are given an integer array of size n containing elements in the range 0 to n-1. Now count the frequency of all elements.

13. Given an array where every element occurs three times, except one element which occurs only once. Find the element that occurs once.

Input: arr[] = {12, 1, 12, 3, 12, 1, 1, 2, 3, 3} Output: 2

14. Given a positive integer n, count the total number of set bits in a binary representation of all numbers from 1 to n.

Examples:

Input: n = 3

Output: 4

Input: n = 6

Output: 9

15. Write a function Add() that returns the sum of two integers. The function should not use any of the arithmetic operators (+, ++, –, -, .. etc). (solution)

16. Write a Java program to find the smallest of three integers, without using any of the comparison operators.

17. Fibonacci Series (solution)

18. Armstrong Numbers (solution)

19. Check if a number is Even or Odd (solution)

20. Java Program to find GCD of two numbers (solution)

21. Check if a number is a palindrome or not (solution)

22. Check if String is palindrome or not

23. Java Program to calculate Simple interest (solution)

24. Java Program to check a leap Year (solution)

25. Code algorithm for Bubble Sort in Java (solution)

26. Code algorithm for Insertion sort

27. Algorithm for QuickSort (solution)

28. Algorithm for Selection Sort

29. Algorithm for Merge Sort (solution)

30. Algorithm for Heap Sort

31. Java Program to count vowels and consonants in a String (solution)

32. How to reverse String in Java (solution)

33. Java Program to reverse a number (solution)

34. Factorial (solution)

**35. Prime numbers (solution)**You need to write a program to check if the given number is prime or not. If the given number is prime then return true otherwise return false. A prime number is a number that is not divisible by any number except 1 and itself.

36. Area of a triangle (solution)

37. middle elements of the linked list (solution)

38. Count occurrences of characters in String (solution)

39. Check if a number is positive or negative (solution)

40. Swap two numbers without using temp variable

41. How to check if two Strings are Anagram (solution)

42. Check if a number is the power of Two or not (solution)

43. How to check if LinkedList contains loops or cycles? (solution)

44. Program to find the sum of digits in a number (solution)

**45. How to remove duplicates from an array? (solution)**hint - this is a common Java coding problem, you can remove duplicates from array creating a new array of unique elements. To find unique elements use a set and copy array elements there. set will not allow duplicates so you will have an array of unique elements.

46. Find whether a given number is a power of 4 or not

47. Compute the minimum or maximum of two integers without branching

48. Given an unsigned integer, swap all odd bits with even bits. For example, if the given number is 23 (00010111), it should be converted to 43 (00101011). Every even position bit is swapped with the adjacent bit on the right side (even position bits are highlighted in the binary representation of 23), and every odd position bit is swapped with an adjacent on the left side.

49. Given an array in which all numbers except two are repeated once. (i.e. we have 2n+2 numbers and n numbers are occurring twice and remaining two have occurred once). Find those two numbers in the most efficient way.

50. Write an Efficient C Program to Reverse Bits of a Number

51. Count number of set bits in a number (solution)

52. Given two signed integers, write a function that returns true if the signs of given integers are different, otherwise false. For example, the function should return true -1 and +100 and should return false for -100 and -200. The function should not use any of the arithmetic operators.

53. LRU cache implementation.

**Further Reading**Grokking the Coding Interview: Patterns for Coding Questions

Data Structure and Algorithms Analysis - Job Interview

Data Structures and Algorithms: Deep Dive Using Java

Algorithms and Data Structures - Part 1 and 2

From 0 to 1: Data Structures & Algorithms in Java

Cracking the Coding Interview - 189 Questions and Solutions

## No comments:

## Post a Comment

Feel free to comment, ask questions if you have any doubt.