Good Questions For Coding Placements
Good Questions For Coding Placements
Integer
Q1. Prime or not.
Q2. All primes btw two no.s. VTK/VVVIP
Q3. GCD and LCM of no.s. VTK/VVVIP
Q4. Prime factorization of no. (pepcoding)
Q5.pythagorean triplets (large no. in consideration) VTK/VVVIP
Q6.The Curious Case Of Benjamin Bulbs.
Q7.Convert decimal to any base no. VTK/VVVIP
Q8. Any base to decimal.
LIST/ARRAY
https://javarevisited.blogspot.com/2015/06/top-20-array-interview-questions-and-answers.html#axzz6udEPakOc
Q0. Print all Subarrays.
Q1. Find the second largest no. in the list.
Q2. Reverse the given list without using direct reverse method.
Q3. Left rotate list by one.
Q4. Left Rotate by d places.
Q5. Find Immediate Smaller Than
X
Given an array arr [] of size N containing positive integers and an integer X, find the element in the array which is smaller
than X and closest to it.
Example 1:
Input:
N = 5
Input:
N = 5
arr [] = {1 2 3 4 5}
X = 1
Output: -1
Explanation: No value is smaller than 1.
Your Task:
You don't need to read input or print anything. You need to complete the given function immediateSmaller() which
takes arr, N and X as input parameters and returns the closest element that is smaller than X. If no such element exists,
return -1.
Input:
N = 11
arr[] = {1,1,2,2,3,3,4,4,4,4,5}
x = 4, y = 5
Output: 4
Explanation:
frequency of 4 is 4.
frequency of 5 is 1.
Q7. Given an unsorted array arr[] of size N, rotate it by D elements in the counter-clockwise direction.
Example 1:
Input:
N = 5, D = 2
arr[] = {1,2,3,4,5}
Output: 3 4 5 1 2
Explanation: 1 2 3 4 5 when rotated
by 2 elements, it becomes 3 4 5 1 2.
Example 2:
Input:
N = 10, D = 3
arr[] = {2,4,6,8,10,12,14,16,18,20}
Output: 8 10 12 14 16 18 20 2 4 6
Explanation: 2 4 6 8 10 12 14 16 18 20
when rotated by 3 elements, it becomes
8 10 12 14 16 18 20 2 4 6.
Your Task:
Complete the function rotateArr() which takes the array, D and N as input parameters and rotates the array by D
elements. The array must be modified in-place without using extra space.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
If not able to solve watch this video https://www.youtube.com/watch?v=ENcnXXiRT6E
Q8. Find if the list is sorted using O(n) time complexity.
Q9. How to find the missing number in integer array of 1 to 100?
Q10. How to find duplicate number on Integer array ?
An array contains n numbers ranging from 0 to n-2. There is exactly one number is repeated in the array. You need to write a
program to find that duplicate number.
Example- intlist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 3].So here 3 is duplicate. Solve without using count method.
https://leetcode.com/problems/maximum-units-on-a-truck/
https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/
STRING
https://hackernoon.com/20-string-coding-interview-questions-for-programmers-6b6735b6d31c
Q0. For "aaabbccdee", the compressed string will be "a3b2c2de2".
Q0.1 For "aaabbccdee", the compressed string will be "abcde".
Q0.2 String that contains the difference of ASCII values of every two consecutive characters between those characters.
For "abecd", the answer should be "a1b3e-2c1d"
Q0.3 Print all permutations of a string.
Sample Input
abc
Sample Output
abc bac cab acb bca cba
Input: eHello123@
Output: 1
Explanation: String is valid.
Input: hella
Output: 0
Explanation: String is not valid.
Q7. Pangram Checking
You are given a string s. You need to find if the string is a pangram or not.
A pangram contains all the letters of English alphabet at least once.
Input:
s = Abcdefghijklmnopqrstuvwxy
Output: z
Input:
s = Abc
Output: defghijklmnopqrstuvwxyz
Your Task:
You only need to complete the function misssingPanagram() that takes s as parameter and returns -1 if the string is a
panagram, else it returns a string that consists missing characters.
Input:
S1 = bcadeh
S2 = hea
Output: 3
Explanation: We need to remove b, c
and d from S1.
Input:
S1 = cddgk
S2 = gcd
Output: 2
Explanation: We need to remove d and
k from S1.
Input:
N = 4
S = 1111
Output: 6
Explanation: There are 6 substrings from
the given string. They are 11, 11, 11,
111, 111, 1111.
RECURSION
https://www.techiedelight.com/recursion-practice-problems-with-solutions/
N = 5
S = 01101
Output: 3
Explanation: There 3 substrings from the
given string. They are 11, 101, 1101.
“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
HASHING
Q1. Check If there is a subarray with sum 0?
Q2. Checking if we can get palindrome by rearranging strings.
Q3. Check if there is a pair in array with a given sum.
SEARCHING
Q1. Binary search algo .
Q2. Binary search using recursion.
Q3. First occurrence of element using binary search. (gfg)
Q4. Last occurrence of element using binary search. (gfg)
Q5. Count total occurrences of given element using binary search. (gfg)
Q6. Count 1's in binary array (gfg)
Q7. Find floor and ceil for a number in sorted array. i.e number just lower and just higher than it in array
https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/
https://www.youtube.com/watch?v=npmfkF5y_R0
SORTING
Q1. Bubble Sort Algo.
Q2. Selection Sort Algo.
Q3. Insertion Sort Algo.
Q4. Merge two sorted arrays.
Q5. Merge sorted subarrays. a= [10, 15, 20, 25, 6, 12, 14, 40] Sort this array within a .
Q6. Mergesort algo.
STACK
Q1. Stack implementation.
Q2. Balanced parenthesis.
Q3. Get Minimum Value of Stack. VVTTTT / VVVIP
Problem- https://www.youtube.com/watch?v=BhYvZ4kVaug
Solution- https://www.youtube.com/watch?v=Trz7JM610Uc
Q4. Infix to postfix.
Q5. Duplicate Brackets
For ques: https://www.youtube.com/watch?v=4eSFaEOa-l0&list=TLGGatTjsEOfmS8yODA2MjAyMQ&t=18s
Q6. Next Greater to the right
For ques:
QUEUE
Q1. Queue implementation using array.
Q2. Queue implementation using LL.
Q3. Circular Queue implementation.
Q4.Queue using two stacks.
LINKED LIST
Q1.all operations
Q2. Max and Min of Linked list.
Q3. Remove duplicates from a LL. https://www.youtube.com/watch?v=dhLtP3UriEU
Q4. Find nth node from end of LL. VVTTTT / VVVIP
TREE
Q1. traversal(in,pre,post) both recursive and iterative
Q2. Size of tree
Q3. Max in tree
Q4. Search value in tree
Q5. Height of tree.
Q6. Top view of binary tree.
Q7. Level order traversal.
QUES.
Q Decode ways (leetcode)
Q The Bangalore railway authorities have decided to construct the required number of platforms in the station so that
the trains need not wait in order to get the platforms.
Given the arrival and departure times of all the trains that reach a railway station. The task is to find the minimum
number of platforms required for the railway station so that no train waits without the platform.
Write a python function which accepts the arrival time list and departure time list and returns the minimum number of
platforms required.
Sample Input
arrival_time_list = [800,850,600,1120,1050,900]
departure_time_list = [1110,1200,1400,1130,1700,2200]
Step 2: For the second element in the input_stack that is 1, the first element in the
reordered input_queue as per step 1 that is 'C' is moved to the rear of
the input_queue, the input_queue is now reordered as (Front -> Rear) A, B, C
Step 3: For the last element in the input_stack that is 2, the last element in the
reordered input_queue as per step 2 is 'C' is moved to the front, so
the input_queue is now reordered as (Front -> Rear) C, A, B
Assumption:
input_queue and input_stack will always contain at least one element each
input_queue will always contain single character strings
The elements in the input_stack can be either 1 or 2
Sample Input and Output:
input_queue input_stack
(Front->Rear) (Top->Bottom)
'A' 1
'A','B','C' 1,2,1
'x','y','z','o','t' 1,1,1
'X','a','B','C' 1,2,1,2
Q A set of points over a straight line is defined as correlative to some K if the absolute difference between any two
points is a multiple of K. Given N (2 <= N <= 100000) points and some integer K (1 <= K <= 1000). Your task is to
find the largest set which is correlative to K. You can assume that only one largest set exists. N and K will be in the
first line of the input. N lines will follow, each one with a single integer, representing the location of one of the points.
Print the size of the largest set of points which is correlative to K, in the first line of the input. Remaining lines will
contain the points of the set, one per line, in increasing order.
Case 1:
52
1
2
3
4
5
3
1
3
5
Case 2:
64
10
15
12
16
20
32
4
12
16
20
32
Q Print all duplicate words with their frequency in a string which have the vowels in lexicographical order.
We resolve to be good. We resolve to be brave. We resolve to be together.
We 3 resolve 3 to 3 be 3 brave 1 good 1.