0% found this document useful (0 votes)
12 views12 pages

Copy of STEP ASKED QUES

Uploaded by

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

Copy of STEP ASKED QUES

Uploaded by

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

​ ​ STEP ASKED QUESTIONS

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

Given an array return length of max subarray whose sum is zero


She was asked to implement a data structure, from and array, in which every operation
should be of O(1) complexity

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/

My second interview question:


Its a really huge story, of websites and usernames..
I have simplified it and this is the point of the question

Given a list like this:


"a" : [1, 2]
"b" : [54, 8]
"a" : [2, 53]
"c" : [66, 87]
"a" : [77, 90]

u need to return smtg like this:

"a" : [1, 2, 53]


"b" : [54, 8]
"c" : [66, 87]
"a" : [77, 90]

so u just need to merge the lists whose intersection is not null.


list 1 and list 3 were merged because they had a common element 2

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/

I am given an array that consists of heights of various buildings.


To climb to a higher building I can either use bricks or rope. Rope can be used to climb any
distance whereas one brick can only be used to climb one unit of distance... To jump to a
building which is lower in height you don't need any support. Given the number of ropes and
bricks... Can you find weather you will be able to cross all buildings or not
https://leetcode.com/discuss/interview-question/528584/Google-or-Onsite-or-How-Far-Can-
We-Reach-using-Rope-and-Bricks
you are given two sorted arrays and you have to check if they both have any same element

you are given a tree with weights and you have to find maximum time it will take to fill that
tree with water

You have some song lyrics let's say


"Breakfast at tiffany's and bottles of bubbles"
Radio station name is given let's say
"Bob"
I have to display this as
*B* reakfast
At tiffany's and b *o* ttles
Of *b* ubbles

Given a sorted array x for each x we have p given


Eg : x[ ] = 1 3 4 5 7 8
p[ ] = 8 1 5 7 8 9
Find i, j such than p[i] + p[j] +abs(x[i] - x[j]) is maximum.
O(n) should be the time complexity

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

Binary tree, find if a path exists that gives sum = x Solution


Follow up: instead of a top-bottom path, find if a left-node-right path exists

'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

Find the Max sum sub array Max SUm Subarray

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.

Question is, we have multiple inputs, like


set_manager, M, A
set_manager, M, B
is_manager, M, A
Write both functions (set manager sets M as manager of A)
is_manager checks and returns if M is manager of A
One manager can have multiple subordinates, but one subordinate can have only 1
manager
So he focused on checking edge cases and time complexity
Then he asked me about searching algorithms
Then asked some more random questions

1) reverse the bits of a byte


2)u are given some text,
Of the form ("xyz", "integer"),("abc", "character"), u have to print it in a table with neat
indentation and orientation
3) x,y,a,b all less than 50
a+b < 29
a = y are multiples of 5
x > b and b > 20 find the possible values

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.

balance the weight of trees

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

1. You're given a range say [1, 100]


You're also given another list of nums around which you have to cut the range, say [3,4,7] so
you would return [1,2],[5,6],[8,100]

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

remove all occurrences of s2 from s1 for ex Solution


Input: s1: abcdebcfghi
S2: bc
Output: adefghi
Input s1: adfbbbcccgh
S2:bc
Output: adfgh

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.

1. Find the height of the given tree


2. Find the mirror image of the given tree

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]

Que.1 Find the smallest element


Que.2 Sort the array

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

interview 1:kind of solution


​ given, [{id0, queue_time0, execution_time0}, {id1,....},......]
​ cpu core: 1
​ t=0
​ find the order in which the tasks would be executed such that the time required is
minimum.
​ you can only perform the task when queue_time <= t

​ example:
​ [{0,0,3},{1,0,4},{2,1,2}]

​ 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

interview 2: given a 2d array, 3 types of cells, infinite Soldiers, 1 Monster, Empty


​ soldiers can move left right up down
​ how much time you will need to kill all monsters?

​ examples:
​ ​ MSE MSE
​ ​ ESE ES S
​ ​ EEM EEM
hint for 1: use priority queues

Q3 eg
40, 30, 10, 50, 60, 100
Maximum profit = 90 ie when we buy 10 and sell 100

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]

Que.1 Find the smallest element


Que. 2 Sort the array

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

Implement the grep function on a given list of strings.


if a given string matches the target strings then print n strings before and after it.
For example:
AAA
ABB
ABC
AAA
ABA
AAA
ABC
ABC
ADG

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)

1. count all distinct subarrays in an array

2. count pairs of all distinct subarrays Solution


optimise code from brute force to O(n^2)

1): Maximize sum of k elements in array by taking only corner elements


Follow up question: Given another array (called multipliers) of size k, multiply elements in
original array with elements in multipliers and find the maximum sum of corner elements
keeping order of elements in tact.
E.g: A = [1, 0, 6, -1], k = 2
M = [3, 7]
All Sums:
1*3 + 0*7 = 3
1*3 + -1*7 = -4
-1*3 + 6*7 = 39
Maximum sum => 39

Interview 2): Merge 2 sorted linked lists using a new node


Follow up question: Merge 2 sorted linked lists in place. Solution

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:: what is the length of longest ap in binary tree


Interview 2:: max pts existing in a line, in lines formed by n pts

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

1. Had to simulate ghost word game. Need not be optimal. (Tries)


2. A mxn matrix represents mn students giving exams. Given initial prob. of getting caught
for horizontal and vertical passing. It gets halved every time we move down a row. Also,
each student has a sneakiness index. Given the chain through which the chit gets passed,
find the prob. that it reaches the last student without getting caught.
Follow up- Given two students, find the max. prob. of the chit getting passed successfully.

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/

first question was to list all files in a directory.


Second question was to put +, *,(,) at the places which would give the maximum answer
given a vector of binary strings, return the maximum number of strings such that the total
number 0s in them does not exceed m and the total number 1s does not exceed n

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy