Professional Documents
Culture Documents
2. Purchase optimization: (Time limit: 60 mins) Alex is shopping at Ozone Galleria Mall.
There is a dedicated cubicle for a type of product at the shopping center. All the
products sold at the ith cubicle are priced the same, denoted by prices[i]. The cubicles
are arranged such that the price of the products soldat each cubicle are in
non-decreasing order.
● Several queries would be asked about the problem. In each query, the cubicle
number Alex is initially standing at, and the amount of money Alex has is given,
and Alex can travel in the right direction visiting from the current cubicle to the
last cubicle. Alex may buy at most one item from any cubicle visited, but the total
cost of the purchase must not exceed the amount Alex has. Report the maximum
number of products that can be purchased for each query.
● More formally, given an array of n integers, prices, where prices[i] denotes the
price of the product sold in the ith cubicle. The array prices are in non-decreasing
order (i.e., the price[i]≤ price[i+1]), and q queries need to be processed. For each
query, two integers are given:
pos: Alex’s initial position amount: the amount of money Alex has
● Alex needs to visit each cubicle from number pos to n, purchasing at most one
product from each cubicle. For each query, the goal is to find the maximum
number of products that Alex can buy.
3. The first question was an application of two pointer approach and sorting,
4. The second question was a slight modification of reverse-Pair, the modification was that
we need to find the maximum no. of inversions among all numbers(numbers were
unique).
5. https://leetcode.com/problems/longest-increasing-subsequence/
6. https://leetcode.com/problems/sell-diminishing-valued-colored-balls/
7. https://www.geeksforgeeks.org/compute-before-matrix/
8. https://leetcode.com/problems/minimum-falling-path-sum/
9. https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/
10. https://www.geeksforgeeks.org/count-triplets-with-sum-smaller-that-a-given-value/
11. Given a string consisting of letters that indicate directions i.e. ‘L’ for left, ‘R’ for right, ‘U’
for, up and ‘D’ for down, find the minimum length of string that can be obtained after
deleting some characters of the string so that we reach the same destination as the
original string.
12. Given ‘n’ Jars filled with ‘m’ number of Jellybeans. ‘T’ represents the number of
operations performed on these jars. Given a range [a-b] and number of jelly beans to be
filled in the jars lying in the range [a-b], find the number of jelly beans in each jar after
these ‘T’ operations.
13. Question 2: Given a number ‘N’ and an array a[ ], find the number of possibilities of
a[i]-a[j]=N such that i>j. (Could be solved in O( n ) using a HashMap).
14. Question 3: Given the number of nodes and the number of edges connecting these
nodes, arrange these edges such that maximum number of nodes are strongly
connected. Return the number of nodes that could be strongly connected. A node is said
to be strongly connected if that node is connected to every other node in the graph
(Derived a formula for it and solved in O(1) –worked for 10/14 testcases).
Formula: (No:Of Edges*2)=(x^2-x) where x represents the number of strongly connected
nodes. Solve the equation for x. Could be reduced as (1+Math.sqrt(1+(8*edges)))/2. The
approximation produced an error of +(-) 1.
15. Question 4: https://www.hackerrank.com/contests/w1/challenges/volleyball-match
(Solved this using Combinatorics in O(1)).
16. Find the number of islands
17. https://www.geeksforgeeks.org/maximum-profit-by-buying-and-selling-a-share-at-most-
twice/
18. Merging two arrays, largest sum contiguous array, sql query to find nth maximum tuple,
polymorphism, lru cache, routing and finding whether the given two linked list intersect.
19. One ques is from DP(easy one like 0-1 knapsack) and other is Activity Selection
Problem).
20. https://algodaily.com/companies/visa
21. https://workat.tech/company/visa/interview-questions/problem-solving?status=all
22. https://www.codingninjas.com/codestudio/interview-bundle/visa
23. Ninja has been asked to organize a dance competition. Ninja decided that he will take
individual entries and then will divide them into pairs. As part of the entry, he asked the
participants to choose any number. Ninja then thought of a creative method to divide
them into pairs. He decided that he would select a number ‘K’, and then select numbers
from the list that have a difference equal to ‘K’. You need to help Ninja in finding the
number of distinct pairs from the numbers with differences equal to ‘K’.
Example: Let us suppose the numbers are chosen by participants: [2, 6, 5, 2, 3] and K =
3, then the distinct pairs having differences equal to K are: [2, 5] and [3, 6] so print 2.
Note: The list of numbers can contain duplicate numbers, you need to print only the
distinct pairs. For example [2, 2, 3, 4] and K = 1, so you need to print 2 as the two distinct
pairs are: (2, 3) and (3, 4).
Input Format: The first line contains a single integer ‘T’ representing the number of test
cases. The first line of each test case will contain two space-separated integers ‘N’ and
‘K’, where ‘N’ denotes the number of elements of the array that contains the chosen
numbers, and ‘K’ denotes the difference required between the pair elements. The
second line of each test case will contain ‘N’ space-separated integers denoting the
chosen numbers by the participants.
Output Format: For each test case, print a single integer that denotes the distinct pairs
having differences equal to K. Output for every test case will be printed in a separate
line.
Constraints: 1 <= T <= 10^2 0 <= N <= 10^4 0 <= K <= 10^4 0 <= ARR[i] <= 10^9 Where
‘ARR[i]’ is the value of elements of the array. Time Limit: 1 sec
24. Maximum length sub-array having absolute difference of adjacent elements either 0 or
1. Given an array ‘A’ of ‘N’ integers, you need to find the maximum length of the
sub-array such that the absolute difference between the adjacent elements of the
sub-array should be either 0 or 1. A sub-array is a contiguous section of original
elements of the array.
For Example: Let us say A = [2,4,6,7,6,9], then adjacent elements of sub array [6,7,6]
have absolute difference of either 0 or 1 and this is the maximum length sub-array. So
the required answer will be 3.
Input Format: The first line contains a single integer ‘T’ denoting the number of test
cases. The first line of each test contains an integer ‘N’ - number of elements in the
array. The second line of each test case contains ‘N’ space-separated integers that make
up ‘A’.
Output Format: For each test case, print a single line containing a single integer
denoting the maximum length of sub-array having an absolute difference of adjacent
elements either 0 or 1. The output of each test case will be printed in a separate line.
Note: You do not need to print anything, it has already been taken care of. Just
implement the given function.
Constraints: 1 <= T <= 50 1 <=N <= 10 ^ 4 -10 ^ 8 <= A[ i ] <=10 ^ 8 Where ‘T’ is the
number of test cases, ‘N’ is the number of elements in the array, A[i] is an array element
at index ‘i’. Time limit: 1 sec.
27. https://leetcode.com/discuss/interview-question/862371/visa-online-assessment
Example: [1,1,0,1]
Player 1 has the follwoing option:
● Play 0 segment- Player1's score 0 and Player2's score ->3-1=2(3 points for segments with
coin and -1 for no coin segment)
● Play 1 segment- Player1's score 1 and Player2's score -> 2-1=1
● Play 2 segment- Player1's score 2 and Player2's score -> 1-1=0
So the answer is 2.
eg: abcd
operation: 1
b->a and hence aacd
eg: bigbangt
operations: 2
first change one 'b' and the next interation change next 'b'
81. There is an array of length n you have to apply minimum number of operations on the
array elements such that for any pair of adjacent elements (arr[i]%2!=arr[j]%2)(more
formally two even number or two odd numbers should not be adjacent to each other)
you can divide an array element by 2 possibly zero or any number of times dividing an
array elemnt by 2 will be counted as 1 operation.
Constraint:(n<=10^5)
82. Given a root directory, traverse the directory through its sub directories, to each of the
files. Output the list of sets of files having the same content.
Input: '/home'
Output:'/home/users/abc.txt' '/home/test/ijk.csv'
'/home/node/app.js' '/home/node/project1/index.js'
'/home/java/main.java' '/home/java/project2/main.java'
83. Senior Engineer, Coding
Given a Huge dictionary of words, and an input stream, return a set of words, which
exist in the input stream. Input stream: "skfjhhelloasjfh sadiokdjnfn..........."
(Input Stream could be random with or without spaces)
Dictionary: foo
smile
sad
bad
hello .... and so on
Output: hello, sad
84. O(n2) was acceptable, but was asked to give a verbal solution of O(n) (KMP or Z
algorithm).
85. https://leetcode.com/problems/valid-parentheses/
86. https://algodaily.com/companies/visa
87. https://www.codingninjas.com/codestudio/interview-experiences/visa/visa-interview-ex
perience-by-on-campus-nov-2020-505?page_type=v2
88. https://www.codingninjas.com/codestudio/interview-experiences/visa/visa-interview-ex
perience-by-on-campus-aug-2021-1131?page_type=v2
89. https://www.codingninjas.com/codestudio/interview-experiences/visa/visa-interview-ex
perience-by-mudit-garg-off-campus-jul-2021?page_type=v2
90. https://www.codingninjas.com/codestudio/interview-experiences/visa/visa-interview-ex
perience-on-campus-dec-2016-1641?page_type=v2
91. https://www.codingninjas.com/codestudio/interview-experiences/visa/visa-interview-ex
perience-by-426-aman-gupta-t15-on-campus-sep-2022?page_type=v2
92. https://www.softwaretestingo.com/visa-interview-questions/
93. Find 'k' largest element in stream of integers.
Constraints -
1) k can vary for every query
2) Stream can not be stored
94. https://www.hackerrank.com/challenges/array-and-simple-queries
Given two numbers N and M. N indicates the number of elements in the array A[](1- indexed)
and M indicates number of queries. You need to perform two types of queries on the array
A[] .
You are given M queries. Queries can be of two types, type 1 and type 2.
Type 1 queries are represented as 1 i j : Modify the given array by removing elements from
to and adding them to the front.
Type 2 queries are represented as 2 i j : Modify the given array by removing elements from
to and adding them to the back.
Your task is to simply print | A[1] - A[N] | of the resulting array after the execution of M
queries followed by the resulting array.
Note While adding at back or front the order of elements is preserved.
95. https://prepfully.com/interview-questions/visa
LEETCODE QUESTIONS:
1. Find kth largest element in a BST
https://leetcode.com/problems/kth-smallest-element-in-a-bst
2. Explain merge sort.
3. https://leetcode.com/problems/partition-equal-subset-sum
4. Given 2 strings find minimum characters need to be removed to make them anagrams of
each other
https://www.geeksforgeeks.org/remove-minimum-number-characters-two-strings-beco
me-anagram
5. DP question similar to https://leetcode.com/problems/unique-paths-ii/
6. DP question : https://leetcode.com/problems/get-the-maximum-score/
7. Binary Tree Maximum Path Sum :
https://leetcode.com/problems/binary-tree-maximum-path-sum/
8. How Static methods and instance methods take part in multi-threaded application.
9. HashMap internal implementation, changes in java 1.8 onwards.
10. When to override equals and hashcode method.
11. https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-
color/
12. https://leetcode.com/problems/search-in-rotated-sorted-array/
13. https://leetcode.com/problems/3sum/
14. https://leetcode.com/problems/group-anagrams/
15. https://leetcode.com/problems/merge-intervals/
16. https://leetcode.com/problems/strange-printer/
17. https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
18. https://leetcode.com/problems/lru-cache/
19. https://leetcode.com/problems/two-sum/
20. https://leetcode.com/problems/longest-substring-without-repeating-characters/
21. https://leetcode.com/problems/remove-nth-node-from-end-of-list/
22. https://leetcode.com/problems/generate-parentheses/
23. https://leetcode.com/problems/gas-station/
24. https://leetcode.com/problems/design-hashmap/
25. https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
26. https://leetcode.com/problems/degree-of-an-array/
27. https://leetcode.com/problems/maximum-subarray/
28. https://leetcode.com/problems/median-of-two-sorted-arrays/
29. https://leetcode.com/problems/reformat-date/
30. https://leetcode.com/problems/merge-k-sorted-lists/
REDDIT: