Softathalon Interview Questions
Softathalon Interview Questions
Softathalon Interview Questions
Easy -
1) Given an array and a number X, find if there exists 2 elements in array whose sum is X.
(Shivam)
2) Given an array and a number X, find if there exists 3 elements in array whose sum is X.
(Vijay)
3) Find smallest value in a sorted array that has been rotated along a pivot.(Shivam)
4) Given an array of integers. Find the pair in an array which has minimum XOR
value.(Shivam)
5) https://www.geeksforgeeks.org/minimum-delete-operations-make-elements-
array/ (Vijay)
6) https://www.geeksforgeeks.org/maximum-distance-two-occurrences-element-
array/ (Vijay)
7) Next greater element(Shivam)
8) https://www.geeksforgeeks.org/find-sum-non-repeating-distinct-elements-array/
Time - O(n^2) / O(nlogn)
Space - O(1) (Vijay)
9) https://codeforces.com/contest/1150/problem/C (Vijay)
10) No of substrings of string S which are anagrams to another string Z (Vijay)
11) Count number of pairs having xor equal to K (Vijay)
12) Given a complete binary tree, such that level order traversal is sorted.
Find an element K in this tree efficiently. (better than O(n))- Akash
13) Draw a circle without floating point arithmetic (#Microsoft)
https://www.geeksforgeeks.org/draw-circle-without-floating-point-arithmetic/ (Muskan)
14) Split a 3*n array into n triplets (x,y,z) where x<=y<=z such that y1+y2+-----+yn is
maximum (Vijay)
15) https://codeforces.com/contest/1003/problem/D greedy (Ayush)
16) https://practice.geeksforgeeks.org/problems/arrange-the-balls/0
17) https://codeforces.com/problemset/problem/75/C
Medium -
1) https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/
2) https://leetcode.com/problems/shortest-common-supersequence/
3) https://ideone.com/kMqI9d (Vijay)
4) (i) Find minimum steps to sort an array when the operation allowed is swapping
adjacent elements (Vijay)
(ii) Minimum number of swaps to sort an array when any 2 elements can be swapped.
(Muskan)
5) Find the largest subarray whose all elements are distinct (Shivam) Bonus:- O(n)
6) Find the maximum size subset whose xor is K. Bonus:- Print the largest size subset if
present (Vijay)
7) https://www.hackerearth.com/practice/algorithms/dynamic-programming/2-
dimensional/practice-problems/algorithm/vanya-and-gcd-array/(Shivam)
8) https://codeforces.com/contest/1130/problem/C (Vijay)
9) https://codeforces.com/contest/1095/problem/C (Vijay)
10) No of subarrays with K distinct elements (Vijay)
11) https://www.geeksforgeeks.org/rearrange-array-maximum-minimum-form-set-2-o1-extra-
space/(Shivam)
15) https://www.hackerearth.com/challenges/competitive/july-circuits-19/algorithm/xor-
thingy-36fea7be/ (Aayush)
18) Given n red balls and m blue balls. Find the no of ways to arrange the balls %
1e9+7 such that there are atmost k consecutive balls of same color. (1<=n<=100 ,
1<=m<=100 , 1<=k<=100) (Vijay) …. Anybody with soln for values<=1e3 can include it
in hard too!! …. (sure buddy :) )....
19) https://leetcode.com/problems/trapping-rain-water/ (Vijay)
20) Given a tree rooted at 1. You have to remove the maximum no of vertices by
performing atmost K operations. In one operation you choose a leaf and remove all the
vertices from the leaf to all its predecessors. (Vijay)
21) Next permutation for 2nd year asked in many interview (Naman)
22) Given height h[i] of n trees and length of wood ‘w’ to be collected. All the trees
have to be cut at the same height and the length of wood above this height is collected.
Find the height ‘l’ at which the trees should be cut so that exactly ‘w’ wood is collected in
total. (#PhonePe) (Binary Search) (Ridhima)
23) Given n cities connected by bi-directional edges. Some aliens appear magically
in some of the cities. Find the minimum time in which they will reach all the cities.
(Multisource-bfs) (#phonepe) (Ridhima)
24) Given a 3*4 board with ‘X’ marked at cell (1,1) , (1,4) , (3,1) , (3,4) . You need to
fill the remaining cells with numbers from 1 to 9 such that for any cell (x,y) no adjacent
values appear in cells (x,y-1) , (x-1,y) , (x,y+1) , (x+1,y) . (Vijay)
26) You are given a tree (a simple connected graph with no cycles).
Find the maximum number of edges you can remove from the tree to get a forest such that
each connected component of the forest contains an even number of nodes.
https://www.hackerrank.com/challenges/even-tree/problem (Ayush) (greedy)
27) https://www.hackerrank.com/challenges/torque-and-development/problem
(Ayush)
28) https://www.geeksforgeeks.org/painters-partition-problem/ (Amulya)
29) Given n currencies, m linear relations (eg : c1=2*c2, c1=c3/2) between them, q
queries and in each query two currencies are mentioned. For each query, find whether
there is any relation between these 2 currencies, if yes then state the relation otherwise
the answer is no. Queries should be precomputed. (#PhonePe) (Graph) (Ridhima)
30) Given Q queries of the form “x and d” where 1<=x<=1e6 and d is a divisor of x.
Find the numbers which have gcd(j,x) = d , i.e. no of j <=x such that gcd(x,j)=d
(Something related to it was asked in Amazon)
31) https://codeforces.com/problemset/problem/348/A (Ayush) (Binary search)
32) https://www.geeksforgeeks.org/merging-intervals/ (Asked in interviews of
Amazon and Google)
33) https://www.geeksforgeeks.org/find-the-point-where-maximum-intervals-overlap/
34) https://www.spoj.com/problems/PPATH/ (BFS + sieve)
35) https://www.geeksforgeeks.org/maximum-product-subarray/
36) Given a traffic signal with two types of lights - green and red. Two consecutive
signals cannot have red lights. A man starts his journey from his home and has to reach
the destination. In his way, there are N such traffic signals. Find the number of ways the
man can reach the destination crossing the N signals. (The first signal is always green)
(Dp)(Ans: fibonacci(N)) - (Ayush)
37) https://www.hackerearth.com/problem/algorithm/chocolates-41/ (Adhoc) (Ayush)
Hard -
Find the no of substrings of a string A which occur as anagram substrings of another string B
( Easy = 1<=|A|<=100 , Hard= 1<=|A|<=1000 ). (Vijay)
LIS in O(NlogN)
https://codeforces.com/contest/1076/problem/E (Vijay)
https://leetcode.com/problems/cut-off-trees-for-golf-event/
Largest size prefix which occurs as a suffix in a string (Vijay)
Largest size suffix which occurs anywhere in the string as a substring (Vijay)
Given Q queries, with each query consisting of two integers L and R, the task is to
find the total numbers between L and R (Both inclusive), having atmost k set bits
in their binary representation.(1<=L<=R<=1e18). (Shivam)
Given an undirected weighted graph . Answer Q queries - No of connected
components considering edges with weight<=x (Vijay)
Given an array, the task is to divide it into two sets S1 and S2 such that the
absolute difference between their sums is minimum.(Shivam)
https://codeforces.com/contest/1095/problem/E (Vijay)
Number of pairs in an array with bitwise AND = 0. (Aayush)
Multiple Queries for distance between two nodes in a tree. (Aayush)
Problem on Topological sorting + dp (Something like number of ways to reach a
particular node from source). (Aayush)
Given a permutation of numbers from 1 to n, you have to answer Q queries, in
each query L to R is given. You have to reverse the segment from L to R and
output the parity of inversion count. All queries are performed one after another.
(Aayush)
You’re given a read only array of n integers. Find out if any integer occurs more
than n/3 times in the array in linear time and constant additional space.
(Priyanshu) https://www.interviewbit.com/problems/n3-repeat-number/
Given a complete binary tree with sorted levels search for an element ( no extra
space )(flipkart FTE)(Naman)
https://www.geeksforgeeks.org/flipkart-interview-experience-for-sde-1-on-
campus-2019/
Find the maximum frequency digit sum between numbers [a,b] . 1<=a,b<=1e18 (Vijay)
https://stackoverflow.com/questions/1701612/find-number-of-permutations-of-a-given-
sequence-of-integers-which-yield-the-same (Amit)
OOPS - Java/C++
1) Polymorphism(Run Time - Compile Time)
11) How to restrict a class to have only one object max? Ans: Using singleton class
15) Given a program which contain pointer whose address value is 100 and there is another
program which has a pointer with value 100, run the first program there is a breakpoint
before printing address value of pointer, at the time of breakpoint we run second
program in which value of pointer is changed to 200, in the end what will be printed by
first program after breakpoint? (Khyati)
16) How to create threads in java (using runnable and thread class) - (Ayush)
Networking