0% found this document useful (0 votes)
68 views11 pages

Good Questions For Coding Placements

The document discusses various questions related to integers, lists/arrays, strings, recursion, hashing, searching and sorting that could be asked during interviews. It provides examples of different types of questions under each topic, including some that are marked as very tricky or important. It also shares some external links for additional reference material.

Uploaded by

yakshit gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views11 pages

Good Questions For Coding Placements

The document discusses various questions related to integers, lists/arrays, strings, recursion, hashing, searching and sorting that could be asked during interviews. It provides examples of different types of questions under each topic, including some that are marked as very tricky or important. It also shares some external links for additional reference material.

Uploaded by

yakshit gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Questions to revise.

Important: conditions to be kept in mind are highlighted with yellow.


VTK – Very Tricky ques .Must do
https://docs.google.com/document/d/1SM92efk8oDl8nyVw8NHPnbGexTS9W-1gmTEYfEurLWQ/preview?
pru=AAABee9sAds*DGduqD2LXG2T8f3k6tIwWA#
List:
 Integers
 List/Array
 Strings
 Recursion
 Hashing
 Searching
 Sorting

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.

Q9. Multiply two matrices.

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

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

arr [] = {4 67 13 12 15}


X = 16
Output: 15
Explanation: For a given value 16, there
are four values which are smaller than
it. But 15 is the number which is smaller
and closest to it with minimum difference
of 1.
Example 2:

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.

Q6. Who has the majority?


Given an array arr [] of size N and two elements x and y, use counter variables to find which element appears most in the array, x or
y. If both elements have the same frequency, then return the smaller element.
Note:  We need to return the element, not its count.

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.

Q11. How to find largest and smallest number in unsorted array.


Q12. How to find all pairs on integer array whose sum is equal to given number. VTK
https://www.youtube.com/watch?v=8c-GO7gWXrs
Try Hashmap method for sure
Q13. How to sort an array in place using Quick Sort algorithm.
Q14. There is an array with every element repeated twice except one. Find that element?
Q15. Count distinct elements in every window (gfg)
Q16. Largest subarray with 0 sum. (gfg) VTK/VVVIP
Q17. Given array. Print new array with element replaced with positions.
Q18. https://leetcode.com/problems/number-of-good-pairs

Q19. Sum of All Odd Length Subarrays

Q20. Maximum Units on a Truck

https://leetcode.com/problems/maximum-units-on-a-truck/

Q21. Find Words That Can Be Formed by Characters

https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/

Q22. Defuse the Bomb https://leetcode.com/problems/defuse-the-bomb/

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

Q. Split a String in Balanced Strings


Link : https://leetcode.com/problems/split-a-string-in-balanced-strings/
Q1. Reverse a string.
Q2. Searching a pattern in a string.
s1 = "geeks for geeks geeks abc geeks qwe geeks geek" Pattern = "geeks"
Q3. Palindrome check. Example=naman
Q4. Anagram check. (if two strings have same characters but in different order are called anagrams) VTK
Ex- “abcde” “acbed”
Q5. Count Distinct Vowels in String 
Q6. String Validation 
Given a string s representing a password, you need to check if the string is valid or not. A valid string has
the following properties:

 String must have the length greater than or equal to 10.


 String must contain at least 1 numeric character.
 String must contain at least 1 uppercase character.
 String must contain at least 1 lowercase character.
 String must contain at least 1 special character from @#$-*.

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.

Q8. Missing Characters in Pangram 


You are given a string s. You need to find the missing characters in the string to make a pangram.
Note: The output characters will be lowercase and lexicographically sorted.

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.

Q9. TWO CHARACTERS- HACKERANK


Given a string, remove characters until the string is made up of any two alternating characters. When you choose a
character to remove, all instances of that character must be removed. Determine the longest string possible that contains
just two alternating letters.
Example
Delete a, to leave bcdbd. Now, remove the character c to leave the valid string bdbd with a length of 4. Removing
either b or d at any point would not result in a valid string. Return .
Given a string , convert it to the longest possible string  made up only of alternating characters. Return the length of
string . If no string  can be formed, return .
Function Description
Complete the alternate function in the editor below.
alternate has the following parameter(s):
 string s: a string
Returns.
 int: the length of the longest valid string, or  if there are none
Input Format
The first line contains a single integer that denotes the length of .
The second line contains string .
Sample Input
STDIN Function
----- --------
10 length of s = 10
beabeefeab s = 'beabeefeab'
Sample Output
5
Explanation
The characters present in  are a, b, e, and f. This means that  must consist of two of those characters and we must
delete two others. Our choices for characters to leave are [a,b], [a,e], [a, f], [b, e], [b, f] and [e, f].
If we delete e and f, the resulting string is babab. This is a valid  as there are only two distinct characters (a and b), and
they are alternating within the string.
If we delete a and f, the resulting string is bebeeeb. This is not a valid string  because there are consecutive e's present.
Removing them would leave consecutive b's, so this fails to produce a valid string .
Other cases are solved similarly.
babab is the longest string we can create.

 Q10. Separate the no.s -Hackerrank


Q11. Weighted Uniform Strings-Hackerrank
Q11. How do you print duplicate characters from a string?
Q12. How do you find all the permutations of a string? VTK
Q13. How do you print the first non-repeated character from a string? VTK
Q14. How do you check if two strings are a rotation of each other? VTK
Q15. How do you find the length of the longest substring without repeating characters? VVVVVVTKKK / VVVIMP
Q16. Convert given no. to roman numerals.
Q17. Anagram of String  VTK
Given two strings S1 and S2 in lowercase, the task is to make them anagram. The only allowed operation is to remove a
character from any string. Find the minimum number of characters to be deleted to make both the strings anagram.
Two strings are called anagram of each other if one of them can be converted into another by rearranging its letters.

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.

Q18. Binary String 


Given a binary string S. The task is to count the number of substrings that start and end with 1. For example, if the input
string is “00100101”, then there are three substrings “1001”, “100101” and “101”.

Input:
N = 4
S = 1111
Output: 6
Explanation: There are 6 substrings from
the given string. They are 11, 11, 11,
111, 111, 1111.

Q19. Multiply two string without using straight multiply .


Q20. Inverse Of A Number (PEPCODING)
You are given a number following certain constraints.
2. The key constraint is if the number is 5 digits long, it'll contain all the digits from 1 to 5 without missing any and without repeating
any. e.g. 23415 is a 5 digit long number containing all digits from 1 to 5 without missing and repeating any digit from 1 to 5.Take a
look at few other valid numbers - 624135, 81456273 etc.Here are a few invalid numbers - 139, 7421357 etc.
3. The inverse of a number is defined as the number created by interchanging the face value and index of digits of number.e.g. for
426135 (reading from right to left, 5 is in place 1, 3 is in place 2, 1 is in place 3, 6 is in place 4, 2 is in place 5 and 4 is in place 6), the
inverse will be 416253 (reading from right to left, 3 is in place 1, 5 is in place 2,2 is in place 3, 6 is in place 4, 1 is in place 5 and 4 is
in place 6) More examples - inverse of 2134 is 1243 and inverse of 24153 is 24153
4. Take as input number "n", assume that the number will follow constraints.
5. Print it's inverse.

RECURSION
https://www.techiedelight.com/recursion-practice-problems-with-solutions/

Q1. Fibonaci series


Q2. Find if given array is sorted.
Q3. All questions from Coding Ninjas downloaded course. VTK/VVVVVIIIIIPPPPP
Q4. Tower of Hanoi. VTK/VVVVVIIIIIPPPPP
Q5. First occ and last occ in arr using recursion.
“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
Input:

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

Q8. Count Negative Numbers in a Sorted Matrix

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:

Q7. Remove Outermost Parentheses


https://leetcode.com/problems/remove-outermost-parentheses/
Q8. https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop

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]

arrival_time_list = [800,850,600, 1350, 1120,1050,900]


departure_time_list = [1110,1200,830, 1400, 1055, 1130,1700,2200]

Note: Time is provided in 24 hour format.

Q Print all binary strings of length n.


Q Print all binary strings of length n with no consecutive 1.
Q Count all binary strings of length n with no consecutive 1. https://www.youtube.com/watch?v=nqrXHJWMeBc
Q Coin change combination
Q Coin change permutation
Q Building selection https://www.geeksforgeeks.org/count-possible-ways-to-construct-buildings/
Q How to print maximum number of A’s using given four keys
https://www.geeksforgeeks.org/how-to-print-maximum-number-of-a-using-given-four-keys/
Q Find minimum time to finish all jobs with given constraints
https://www.geeksforgeeks.org/find-minimum-time-to-finish-all-jobs-with-given-constraints/

Q Consider an input_queue containing characters as elements and


an input_stack containing integers (integers can be either 1 or 2 only). 

Example for input_queue (Front -> Rear): A, B, C 


Example for input_stack (Top -> Bottom): 2, 1, 2 

Write a function which takes input_queue and input_stack as input parameters and


returns an output_queue which contains the elements of the input_queue but in a
different order. The ordering of elements in output_queue is determined by the
elements of input_stack as mentioned below – 
For every element in the input_stack, input queue is reordered based on the below rule

If the element is 1, then the first element in the input_queue (element at front) will
become last element (element at rear).
If the element is 2, then the last element (element at rear) in the input_queue will
become the first element (element in front).
Example: 
input_queue(Front -> Rear): A, B, C 
input_stack (Top -> Bottom): 2, 1, 2 
output_queue (Front -> Rear): C, A, B

Step 1: For the first element in the input_stack that is 2, the last element in


the input_queue that is 'C' is moved to the front, so the input_queue is now
reordered as (Front -> Rear) C, A, B. 

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 

Step 4: The output_queue should contain the elements as per step 3 which is 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:

For the input provided as follows:

52
1
2
3
4
5

Output of the program will be:

3
1
3
5

Case 2:

For the input provided as follows:

64
10
15
12
16
20
32

Output of the program will be:

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.

You might also like