150 Problem Solving Questions
150 Problem Solving Questions
Operators:
1. IS EVEN? : https://tests.mettl.com/authenticateKey/2bd025dc
2. IS ODD? : https://tests.mettl.com/authenticateKey/dbdac2a9
3. Return last digit of the given number :
https://tests.mettl.com/authenticateKey/454f012b
4. Return second last digit of given number :
https://tests.mettl.com/authenticateKey/9f87004e
5. Sum of last digit of two given numbers :
https://tests.mettl.com/authenticateKey/783a1fcf
6. Is N an exact multiple of M?:
https://tests.mettl.com/authenticateKey/36c4ef58
Loops:
Learn to solve math based number problems (will require loops and maths)
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Number Based:
24. A number is said to be a magic number, if the sum of its digits are calculated till a
single digit recursively by adding the sum of the digits after every addition. If the
single digit comes out to be 1,then the number is a magic number.
for example-
Number= 50113
=> 5+0+1+1+3=10
=> 1+0=1
This is a Magic Number
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
For example-
Number= 1234
=> 1+2+3+4=10
=> 1+0=1
This is a Magic Number
Ex. 6928
6-9= 3
9-2=7
2- 8=6
O/p: 376
Again perform RS
3-7=4
7-6=1
O/P:41
26. Program to print the sum of odd numbers and arrangement of odd sequence
I/P: 361589
Op:315968
i/P:361589
o/p: 315968
28. Arrangement of odd sequence with count followed by even sequence with count
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
i/p:361589
o/p: 31594682
Ex: 143
Output: 341
30. Problem to count the total number of odd and even in the given any digit number
Input = 53467
Ans:
Odd=3
Even=2
31. Problem to check whether all the numbers are arranged in ascending order
Input-1 = 4567
Output: Yes
Input-2 = 4576
Output: No
Input-1 = 12345
Output: Yes
Input-2 = 1245
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Output: No
Pattern Programs
41. No=5
11111
2 5
3 5
4 5
11111
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
42.
00
111
0000
11111
43.
no=5
12
123
1234
12345
44.
no=5
12
123
1234
12345
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
45.
no=5
12345
1234
123
12
46.
no=5
12345
2345
345
45
47.
no=5
12345
2345
345
45
48.
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
no=5
5 4 3 2 1
4 3 2 1
3 2 1
2 1
49.
no=5
10
101
1010
10101
50.
No-5
E D C B A
D C B A
C B A
B A
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
51.
No-5
E D C B A
A B C D
D C B
B A
52.
Print braces pattern program
int n=2
Output:
{}
{ } {{ }}
53.
Hour glass pattern
n=8
********
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
********
54.
Pyramid pattern
55.
Diamond pattern
Arrays
56. Missing number in an array of shuffled order
Input:[3, 7, 1, 2, 8, 4, 5]
Output:6
57. Second largest number in an array
Input:[12, 35, 1, 10, 34, 1]
Output:34
58. Re-arranged array by small – largest combination
Input: [1, 3, 5, 2, 8, 7, 4]
Output:[1, 8, 2, 7, 3, 5, 4]
59. Remove all duplicates in an array sample input and output
Input:[1, 2, 2, 3, 4, 4, 5]
Output:[1, 2, 3, 4, 5]
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
int a[] = { 50, 20, 150, 20, 50, 10, 30, 10, 10 };
int a[] = { 10, 20, 30, 40, 50, 25, 35, 45 }; d=2
Expected OP: 30 20 10 45 35 25 50 40
Input={40,20,10,50,20,10,30,40}
Output:
40 -> 2
20 -> 2
10 -> 2
50 -> 1
30 -> 1
63. Program to find the frequency count of every number in an array in ascending
order
Input={40,20,10,50,20,10,30,40}
50->1
30->1
40->2
20->2
10->2
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
64. Program to find the frequency count of every number in an array in descending
order
Input={40,20,10,50,20,10,30,40}
40->2
20->2
10->2
50->1
30->1
67. Given an array of integers, return a new array such that each element at index i of
the new array is the product of all the numbers in the original array except the one
at i.
For example, if our input was [1, 2, 3, 4, 5], the expected output would be
[120, 60, 40, 30, 24]. If our input was [3, 2, 1], the expected output would be [2, 3, 6]
68. Given an integer array find the duplicate element which has the longest distance
int arr[]={1,2,3,1,3,4,2,5,6,1};
O/p: 1
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
69. Given an integer array using searching element place the incremented number
next to searching number
Input = {10,20,10,30,14,40,60,10}
Search=10
Output={10,1,20,10,2,30,14,40,60,10,3}
Output : 10 3
20 4
Output : 5 1
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Explanation:
Given an integer array arr[], print all distinct elements from this array. The given
array may contain duplicates and the output should contain every element only
once.
83. Given an array nums of distinct integers, return all the possible permutations. You
can return the answer in any order.
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
84. Given a 2D integer array matrix, return the transpose of the matrix.
Explanation:
The transpose of a matrix is the matrix flipped over its main diagonal, switching
the matrix's row and column indices.
85. Given an m x n matrix, return all elements of the matrix in spiral order.
86. Given three arrays A1, A2, A3. Find the count of the distinct values: A1 values
should not present in both A2 and A3. Similarly for A2 and A3
Input:[1, 2, 3, 4]
[3, 4, 5, 6]
[6, 7, 8]
Output:
87. Given an array of integers greater than zero, find if it is possible to split it in two
subarrays (without reordering the elements), such that the sum of the two
subarrays is the same. Print the two subarrays.
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Input: Arr[] = { 1 , 2 , 3 , 4 , 5 , 5 }
Output: { 1 2 3 4 }
{5,5}
88. Given an array of size N where the array elements contain values from 1 to N with
duplicates, the task is to find the total number of subarrays that start and end with
the same element.
Input: A[] = {1, 2, 1, 5, 2}
Output: 7
89. You are given an array arr, and your task is to find the majority element an element
that occurs more than half the length of the array (i.e., arr.size() / 2). If such an
element exists return it, otherwise return -1, indicating that no majority element is
present.
Input : arr[] = [1, 1, 2, 1, 3, 5, 1]
Output : 1
90. Given an array arr[] of size n and an integer k, the task is to insert a duplicate of k
adjacent to its every occurrence. Keep array's original length same by removing the
elements from the back.
Input: arr[] = [1, 0, 2, 3, 0, 4, 5, 0], K = 0
Output: [1, 0, 0, 2, 3, 0, 0, 4]
91. Given an array arr[], the task is to find the subarray that has the maximum sum and
return its sum.
Input: arr[] = {2, 3, -8, 7, -1, 2, 3}
Output: 11
95.
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Each of these are four digit numbers within the range >=1000 and <=9999
i.e
1000<=input1<=9999
1000<=input2<=9999
1000<=input3<=9999
you are expected to find the key using the below formula
[smallest digit in the tens place of all three numbers][LARGEST digit in the units
place of all three numbers]
Assuming that the 3 numbers are passed to the given function.Complete the
function to find and return the key.
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Strings
97. Validation of an Identifier
98. Total Number of Words in a given string
99. Adding the number from the String input
Input: 5ingt44t3
Output: 52
Input: aaaabbcccc
Output:a4b2c4
Input: engineering
Output: e 3
I/p: “repeatable”
O/p: e:3
a:2
r:1
p:1
t:1
b:1
l:1
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
103. Program to remove the palindromic string from the given input string
104. Program to count the characters which has lower followed by higher
Input="accept Van"
Output=2
inp1="fi_er";
inp2="Fever:Filer:Filter:FIxer:Fiber:Fibre:Tailor:Offer";
106. Program to reverse either odd or even position based on the input
inp1="chennaicity"
inp2="odd"
Output:ctecnainihy
107. Program to process the string with unique characters count within the
distance
Input2='a';
Output=7
input="aaabccccddaaaaab"
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
output=a3bc4d2a5b
"dogo"
"godo"
Output: true
110. Half of the string to lower case and remaining half to uppercase
I/P:”helloworld”
O/P:”helloWORLD”
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
120. Given a string s of lowercase English letters, the task is to find the first nn-
repeating character. If there is no such character, return '$'.
Input:"aabcdd"
Output:'b'
Input1:listen
Input2:silent
Output:is anagram
122. Given a String, the task is to insert another string in between the given String
at a particular specified index in Java.
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Input:originalString = "WelcomeJava",
stringToBeInserted = "to",
index = 4
Output:"WelcometoJava"
123. Delete all the common elements of two string and concatenate both
a="aaaa"
b="aabbbb"
output:"bbbb"
Input: 000012356090
Output: 12356090
Input:programming
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
133. User ID Generation: Joseph's team has been assigned the task of creating
user-ids for all participants of an online gaming competition Joseph has designed
a process for generating the user-d using the participant's First_Name ,Last_Name,
PIN code and a number N The process defined by Joseph is as
below –
Step1- Compare the lengths of First_Name and Last_Name of the participant. The
one that is shorter will be called “Smaller Name” and the one that is longer will be
called the “longer Name” if both First_Name and Last_Name are of equal Length
,then the name that appears earlier in alphabetical order will be called “Smaller
Name” and the name that appears later in alphabetical order will be
called the “Longer Name”
Step2 - The user-should be generated as below –
Last Letter of the smaller name + Entre word of the longer name + Digit at position
N in the PIN when traversing PIN from left to right +Digit at position N in the PIN
when traversing the PIN from right to left
Step3 - Toggle the alphabets of the user-id generated in step -2 i.e. upper-case
alphabets should become lower-case and lower-case alphabets should become
upper-case.
Let us see a few examples
Example-1 - If the participant's details are as below
First Name = Ray
Last Name =Roy
PIN = 560037
N= 6
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Step1 - Length of Last_Name is less than the Length of First_Name, so the Smaler
Name is “Roy” and the Longer Name is “Rajiv”
Step2 - The user id will be = Last Letter of the smaller name +Entre word in the
longer name + Digit at position N in the PIN when traversing the PIN from left to
right +Digit at position N in the PIN when traversing the PIN from right to left
=Last Letter of “Roy”+ Entre word in Rajiv+ 6th Digit of Pin from left + 6th Digit of
PIN from right
=y+ Rajiv+7+5
Therefore, user-id=yRajiv75
Step3 -Toggle the alphabet in the user-id. So,user-id = YrAJIV75
135. You’re given the size of the array and an array of integers; print the number
of times each integer has occurred in the array.
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Sample Input 1: 10
1233414512
Sample Output 1:
1 occurs 3 times
2 occurs 2 times
3 occurs 2 times
4 occurs 2 times
5 occurs 1 times
Key=1321
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
You are provided with 3 numbers: input1, input2 and input3. Each of these
are 4 digits’ numbers within >=1000 and <=9999 i.e., 1000<=input1<=9999
1000<=input2<=9999 1000<=input3<=9999 You are expected to find the key using
below formula:
Key = Sum of Largest digits of each number + Sum of Second Largest digits of each
number for Example, input1=3521, input2=2452 input3=1352
Input1 = 45678
= 3 (i.e 3+0)
142. Ranking
Given the array of elements where you have to print the rank of every
elements in the array without changing the position
Input:
{10,5,20,30,1,4,25}
Output:
4, 3, 5, 7, 1, 2,6
Detective Buckshee junior has been approached by the shantiniketan kids society
for help in finding the password to the games complex.After hearing the
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
A number is stable if each of its digit occur the same number of times, i.e the
frequency of each digit in the number is the same.
Similarily,A number is unstable if the frequency of each digit in the number is NOT
the same.For eg:221,4314,101,233,58135,101 are examples of unstable numbers.
For example:
Key= Smallest number from input1+ Smallest number from input2+ Smallest
number from input3+ largest number from input1+ largest number from input2+
largest number from input3
Key=1+2+1+5+5+5=19
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
1, 2, 3, 1, 2, 3, 4
Output:
1, 2, 3, 4
Given an array of N integers and we have to find its second largest element using
Java program.
Input:
Output:
Input:
Output:
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
Given an array of integers and we have to count total negatives, positives and zeros
using java program.
Input:
Output:
Zeros are: 1
149. Given an integer array of size N. Write Program to find sum of positive square
elements in the array.
Sample input 1:
1234
Sample output 1:
30
Explanation :
(1 + 4 + 9 + 16) = 30
Sample input 2:
-1 -2 -3 -4
Sample output 2:
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)
VEL TECH HIGH TECH
Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
Approved by AICTE - New Delhi, Affiliated to Anna University - Chennai
Accredited by NBA, New Delhi & Accredited by NAAC with "A" grade & CGPA of 3.27
30
Explanation:
(1 + 4 + 9 + 16) = 30
150. Given an integer array of size N, write a program to sort the array;
Sample input 1:
4
2413
Sample output 1:
1234
Sample input 2:
5
15753
Sample output 2:
13557
With reference to NBA – SAR Guideline: Criteria No. 4.5 & 7.3(a)