Copy of STEP ASKED QUES
Copy of STEP ASKED QUES
Given a list of words and a string, two players can append a character to the string such that
it should form into the prefix of any word in the given list but string should not be sama as
any word in the dictionary (ex b is string and it can be appended till brea as bread is in given
list)
Question is to simulate the game where 2 players would append one by one untill it's equal
to the word
Interview 1:
Input would be a 3 digit number. Give all possible combination of words for the number
Given 1 - has no letter corresponding to it
2 - A,B,C
3 - D,E,F
Just like the old button phone keypad
For example if input is 234
Output would be: adg,adh,adi,bdg and so on
Given N employees, each of whom have one manager each, except the CEO and each
employee has a popularity rating. If a manager goes, then immediate employees to him
cannot go. Now maximise the total popularity by choosing whom to invite whom to not
Solved using tree and kept a hashmap so as to optimise time complexity
Interview 2:
Given a matrix find the longest chain path
A chain path means, suppose if we take an element, then any element in the same row or
column that is greater than the present element will be added to the path.
So the length of the longest path is what we have to find
Interview: given distance and taxes bw two cities find the most expensive ticket
Where the ticket cost is abs of dist bw ye cities and tax values.
https://stackoverflow.com/questions/6989855/how-do-i-find-the-path-with-the-biggest-sum-of
-weights-in-a-weighted-graph
Give an array and a value k, you need to return maximum sum from the ends(this was one
the questions from anshul's sheet on leetcode)GFG Link
I am given a list of strings. And each string is a message, of format, <John> Hi, Hello there!
Etc..And I need to find the user who has the maximum word count.
The words can be anything, as long as they have at least 1 alpha numeric character, And
you have to return the top n names with the word count
https://leetcode.com/discuss/interview-question/378774/Google-or-Onsite-or-Sort-a-Partially-
Sorted-Array/341287
https://www.geeksforgeeks.org/search-an-element-in-a-sorted-and-pivoted-array/
The naive approach is O(n ^ m) just see if there's something common between the lists..
n is number of lists
m is number of eles in each list
The better approach is to use union find u'll get a complexity of O(n * m)
https://leetcode.com/problems/accounts-merge/
you are given a tree with weights and you have to find maximum time it will take to fill that
tree with water
check if two arrays have the same elements with the same frequency with all complexity
reduction and all.
given source and sink nodes of graph find the minimum weight path between them. He also
asked me how would check if a tree is a binary search tree
Number represented by linked list with head pointing to most significant digit, add 1 to it
without recursion, reversing, converting to int or using extra space
'm given transactions, I have to simplify them in such a way that the total transactions are
less than n.
Second interview me pehle he asked a^b, then i,j such that a[i]+a[j] = x, then Bridge and
torch puzzle
A->B 10
B->C 5
A->C 10
Now simplify ki less than 3 hi ho transactions
https://harshitjain.home.blog/2019/08/21/find-moving-average-of-last-n-numbers-in-a-stream/
https://leetcode.com/discuss/interview-question/219173/facebook-remove-every-alternate-el
ement-from-a-circular-linked-list
https://leetcode.com/problems/moving-average-from-data-stream/
https://leetcode.com/problems/sliding-window-median/
give directories find files inside and return all the files.
1st interview: You are given a matrix in which 1s represent land and 0s represent water. You
have to find how many islands are there. Solution
2nd interview: How many squares can be formed by the given coordinates.
Interview 1:
- Tell frequency of a target element in a sorted array
Best complexity: logn
- How to sort a stack with other stacks (He asked me to show with an example how I would
do it and complexity and stuff.. and didn't ask for code because no time) Solution
Interview 2: Max sum of subarray from ends of the array
You have been given 1) lower bound 2) upper bound (both integers) and 3) n
Return n unique random integers between lower and upper bound - assume you have a
function which generates random numbers (ofc) Solution
You are given N coordinates from x1, x2, x3... till xN in ascending order in the axis. All
coordinates have a value associated with them pi (not given in any particular order). The
task was to maximize the expression (pi + pj + |xi-xj|)
Interview 2
Was testing mostly my concepts, time complexities and how I write and figure out edge
cases. He gave me 3 Qs (all easy) on searching sorting etc.
You are given a racetrack length, running speed, walking speed, and the maximum metres
that you can run. You have to find out the min time to cover the racetrack.
Follow up ques:
Along with all the previous data you are given a vector that contains different segments that
you can either run or walk. You have to cover the whole path in minimum time.
Interview 2:
https://www.geeksforgeeks.org/maximize-sum-of-k-elements-in-array-by-taking-only-corner-
elements/
Follow up question:
You are given an array A, and an array M(of size k) and you are supposed to maximize A[i] *
M[i] + A[j]* M[j] and the constraint is that you have to take only k corner elements from array
A.
given these people working in a company and every employee has one manager except the
CEO. So thr is a party and evry member of the company has a number which is the likability
of that employee so for the party we need to find the maximum likability that we can get. And
the condition is if the manager is going to the party the employees can't go. ( So she told me
to write a pseudocode for my approach but as she took so much time just to explain to me
what the ques was so I told her my approach she said almost correct then she said how will
u code it so I wrote a code which was sth like pseudocode which she asked for but I couldn't
come up with the best approach in the given time and I don't think she actually got my full
approach, as I was explaining her the last part of the code but it was over time so she said I'll
end the interview here)
3 CEO ( em1)
2 emp1 (emp2, emp3)
2 emp 2 (emp4, emp5)
3 emp3
2 emp4
1 emp5
So the number before the emp is thr likability
\And the list after them are the employees they are manager to
First interview: You're given an nxn tic tac toe game where 0 represents empty, 1 represents
X and 2 represents O. So given a state of the board, return the winner if there is a winner.
Now the catch is that this is not a normal tic tac toe game, you're also given 'k' which
represents the number of consecutive 1's or 2's you need to win.
Example: if there's a 4x4 board and k=2 then even 2 consecutive 1's will mean 1 won. And
these 1's and 2's can come consecutively vertically, horizontally or diagonally.
12/15/20, 6:04 PM - +91 99111 93418: Second interview: i had 2 questions here
2. Given two sorted arrays of sizes m and m+n merge the two into the second array such
that the second array is also sorted with all the elements.
Interview 1. A spider is initially at the root node of a binary tree(t = 0) and the spider jumps
down to the child nodes with each unit time. If it encounters a leaf node it stays there. Write
a program which predicts the probability of finding the spider in any given node.
Interview 2. Given a non-negative integer array and a number k, find the length of the
smallest subarray whose sum is k. Solution
interview 1
given a value n rotate an array n times
given a circular linkedlist and a vector of pointers return the no of blocks in the linkedlist.
like list is 1-2-3-4-5 and vector of pointers is [1,2,4] so one block would be 1-2 and other
would be 4 so output is 2 blocks.
interview 2
given a list of strings of chats with usernames and the chat text in every string print the user
with most no of words in the chat and the username also
1.given starting time and execution length of few tasks which are already scheduled, i am
given a new task which can be scheduled if it doesn't overlap w existing tasks.
If it can be scheduled, add it to list.
Tasks are sorted, after sdding new task it should be sorted only.
2. An array of integers is given, return the length of the *minimum* subarray whose sum = k.
Interview 1:
There is this array such that
0 < i < arr.length() - 1
arr[0] < arr[1] < . . . . < arr[i]
arr[i] > arr[i+1] > . . . > arr[length - 1]
1234987
Que. 1
Okay one file was give with format
WireName1 : Resistance value
WireName2 : Resistance value
and so on
We have to read that file and list it so that the resistance value in decending order
Que. 2:
We have given two file such that
File 1:
A : <msg>
B : <msg1>
C : <msg3>
File 2:
A : <msg>
B : <msg5>
D : <msg6>
We have to compare two files and make a file in which we have to print whether keys in file1
is changed, deleted or remain unchanged or new message in added in file2.
And if msg is changed then print that for key1 it is changes from msg1 to msg2
ans: 0, 2, 1
explaination:
at t= 0, 0 and 1 are queued, 0 will be executed as minimum execution time
now t = 3, 1 and 2 are queued, 2 will be executed
lastly 1
Q3 eg
40, 30, 10, 50, 60, 100
Maximum profit = 90 ie when we buy 10 and sell 100
In a BST, two elements are swapped . We have to bring back the original BST Solution
Given an array of integers, find the length of longest sub-array where sum of elements is 0.
Solution
Target: ABC, N = 2
output:
AAA
ABB
ABC
AAA
ABA
AAA
ABC
ABC
ADG
each string can only be printed once and optimise from O(n^2) to O(n)
Interview 1:
There are some rocket positions given and each rocket has a corresponding power. When it
bursts all rockets with the range of its position + power get burst.
Task is to place a rocket at any position on the left of the leftmost rocket and then assign it
some power in such a way that maximum no of rockets are left to be light up.
While bursting, only the power of initial is added and not the ones that get bursted because
of it. Find the Maximum no of rockets that can be left to lite up .
Interview 2:
Given some cities on a line, each city has some tax associated with it. cost of flight from one
city to another is distance between then plus the tax in both the cities.
Find the maximum cost flight that exists.
1)
a.given a linked list find the last nth element Solution
b. given two sorted arrays merge the two in one array(i. e second array) Solution
2) Given an array find whether all the elements can be found out by binary search.
Eg 3, 1
3- True
1-False
1) You are given a number you have to reduce it to 1 in the minimum number of operations.
You can either divide the number by 2 or by 3 or subtract 1 from it.
2) There is a single one way road. There are a number of cars going one after the other. You
know the speeds of the cars. If the second car can catch up to the first then both the cars will
go in the speed of the first car. If it can’t catch up then both cars will continue to go in their
own speeds.
Eg : [10, 20, 16, 36, 100, 80]
Answer : [10, 16, 16, 36, 80, 80]
Here 100 can catch up to 80, so now both will travel at 80. 36 can’t catch up to 80 so it will
remain 36. 16 can’t catch up to 36 so it will remain 16. 20 can catch up to 16 so it will travel
at 16 when it catches up. And so on
Int 1:
1q based on binary search
Another q idk what it is based on, most longest decreasing (increasing)subsequence logic (i
realised it only after the interview, no time to do it )
Int 2:
Bit manipulation and some encoding of bits related Question- 2 parts
Interview 1: Given a set of coordinates in coordinate plane, return how many squares are
possible
Interview 2: Given a matrix, allowed movements are left, up, down, right only if neighbour
has value less than = current, is it possible to reach (m-1,n-1) from (0,0)
Interview 1 : Implementation of n-ary tree and the probability distribution of time taken by
insect to reach the leaves
Interview 2 : Given an array if size N, select K elements only from the ends so as to
maximise the sum
In first question, there are some words given in a dictionary. You start with an empty string,
and each player alternatively appends a character in that string. The string after appending
that character should be such that it is a prefix in any of the words in the dictionary, but it
should not be exact same as any word in the dictionary(game ends in such case).
1) You are given a vector of strings, a integer contextRequited and a string findWord. U have
to return a contextRequired number of words before and after the findWord if find word is
present in the vector.
Eh- vector =[ occasional, for, it, and, made, happy, it, then, life]
findWord = it , contextRequired = 1
Then output = [for, it, and, happy, it, then]
2) Given an array of numbers, return the largest sum of k elements. You can only choose the
k elements from the ends.
Interview 1
Given N points (x1 < x2 < x3 .... < xN) each point has a value pi
Find out (i, j) such that pi + pj - |xi - xj|
Interview 2
Given an array that stores pointers to nodes of a doubly linked list, find out how many
connected units are present in the linked list
https://www.geeksforgeeks.org/longest-subarray-in-which-absolute-difference-between-any-t
wo-element-is-not-greater-than-x/?ref=lbp
https://www.techiedelight.com/find-maximum-sum-root-to-leaf-path-binary-tree/
Given 2 strings, 1 is the correct word, 2nd is a stretched version (might be might not be)
return True if second word can be reduced to the first one
Eg: hello, hheeeellooo (true)
Taneesha, Taanneshaa (false)
Correct approach: Two pointer
Terrible interview owing to nervousness.
*Interview 2 :*
You are given a file path : "/app/home/foo"
Print it as
-- app
-- home
-- foo
Follow up : you are now given list of paths, print them in alphabetical order, putting sub
directories in directories etc
Eg :
"/app/home/foo", "app/home/bar", "/blah/moreblah", "/images/image", "/app/services/",
"/app/customer/", "text.json"
Output :
-- app
-- home
-- foo
-- bar
-- services
-- customer
-- blah
-- moreblah
-- images
-- image
-- text.json
You are given an array of integers.What is the minimum number of pair swaps (swap
element at index i with element at index j) needed so that all the elements at even indices
are divisible by two and all the elements at odd indices are not.