Professional Documents
Culture Documents
com
Arrays 75/75
Binary Search 75/75
Easy 65/65
Medium 75/75
Problem Solving 130/130
Search 5/5
Strings 50/50
Trees 5/5
Recruiter/Team Comments:
No Comments.
Correct Answer
QUESTION DESCRIPTION
A string is a pangram if it contains all letters of the English alphabet, ascii['a'-'z']. Given a list of strings,
Score 50
determine if each one is a pangram or not. Return "1" if true and "0" if false.
Example
pangram = ['pack my box with five dozen liquor jugs', 'this is not a pangram']
the string 'pack my box with five dozen liquor jugs' is a pangram , because it contains all the letters 'a'
through 'z'
the string 'this is not a pangram' is not a pangram
Assemble a string of the two results, in order. The result is '10'.
Constraints
1 ≤ n ≤ 100
Each string pangram[i] (where 0 ≤ i < n) is composed of lowercase letters and spaces.
1 ≤ length of pangram[i] ≤ 105
Input from stdin will be processed as follows and passed to the function.
The first line contains an integer n, the size of the array pangram.
The next n lines each contain an element, pangram[i], where 0 ≤ i < n.
Sample Case 0
Sample Input 0
STDIN Function
Parameters
----- ---------
----------
4 → pangram[]
size n = 4
2/15
we promptly judged antique ivory buckles for the next prize → pangram[]
= ["we promptly judged antique ivory buckles for the next prize",
we promptly judged antique ivory buckles for the prizes
"we promptly judged antique ivory buckles for the prizes",
the quick brown fox jumps over the lazy dog
"the quick brown fox jumps over the lazy dog",
the quick brown fox jump over the lazy dog
"the quick brown fox jump over the lazy dog" ]
Sample Output 0
1010
Explanation 0
pangram[0] = True
pangram[1] = False
pangram[2] = True
pangram[3] = False
The strings pangram[0] and pangram[2] are pangrams, and the others are not.
The result is '1010'
STDIN
Function Parameters
-----
-------------------
4
→ pangram[] Size n = 4
cfchcfcvpalpqxenhbytcwazpxtthjumliiobcznbefnofyjfsrwfecxcbmoafes tnulqkvx
oxhctvhybtikkgeptqulzukfmmavacshugpouxoliggcomykdnfayayqutgwivwldrkp
gpecfrak zzaxrigltstcrdyhelhz rasrzibduaq cnpuommogatqem
hbybsegucruhxkebrvmrmwhweirx mbkluwhfapjtga liiylfphmzkq
Sample Output 1
0000
Explanation 1
pangram[0] = False
pangram[1] = False
pangram[2] = False
pangram[3] = False
No string is a pangram.
The result is '0000'
INTERVIEWER GUIDELINES
Hint 1
How can you keep track of when a character has been seen? Answer: Have a seen array of 26
integers initialized to zero. As a character is seen, update the array at the index ord(character) -
ord('a') to 1. Ignore spaces.
Hint 2
How will you know when all letters have been seen?
3/15
Answer: Each time you update the seen array, increment a counter.
Solution
Skills: Iterating through strings, problem solving, data structures (set or array)
Brute Force Approach: A simple solution that analyzes every character of the string is to create a set
from the alphabet, create a set from the string, remove the space character from the set and get their
intersection. If the intersection equals the alphabet set, the string is a pangram. Creating a set takes
O(n) running time.
Optimal Solution:
The most efficient solution starts with an seen array of 26 zeros, and a counter initialized to 0. Iterate
through the string, checking if a character has already been seen. If it has not, update the value in the
seen array and increment the counter. When the counter equals 26, it is a pangram. If you reach the
end of the string and the counter is less than 26, it is not a pangram. Note that the test cases are such
that a solution will work even if they iterate through all characters in every string. A minor optimization
is to break out of the loop when the counter reaches 26.
def isPangram(pangram):
# Write your code here
answer = ''
for sentence in pangram:
seen = [0] * 26
count = 0
for c in sentence:
if not c == ' ':
idx = ord(c) - ord('a')
if seen[idx] == 0:
seen[idx] += 1
count += 1
if count == 26:
break
answer += '1' if count == 26 else '0'
return answer
Complexity Analysis
Follow up Question
What if we just wanted to identify if a subset of the alphabet is included in a string? For
example, the subset is all the characters in "aeiou"?
Psuedo Code -
CANDIDATE ANSWER
1 /*
2 * Complete the 'isPangram' function below.
3 *
4 * The function is expected to return a STRING.
5 * The function accepts STRING_ARRAY pangram as parameter.
6 */
7
8 function isPangram(pangram) {
9 // Write your code here
10 let results = ''
11
12 function isStrPangram(str) {
13 const charMap = new Map()
14 let charCount = 0
15 for (let s of str) {
16 if (s !== ' ' && !charMap.has(s)) {
17 charMap.set(s, 1)
18 charCount++
19 }
20 }
21 return charCount === 26
22 }
23
24 for (let str of pangram) {
25 results += isStrPangram(str) ? '1' : '0'
26 }
27
28 return results
29 }
30
31
5/15
TestCase 10 Easy Hidden case Success 5 0.0797 sec 37.4 KB
No Comments
Correct Answer
QUESTION DESCRIPTION
int a = 1;
while (a < n) {
a = a * 2;
}
INTERVIEWER GUIDELINES
CANDIDATE ANSWER
O(n)
O(1)
O(log2(n))
O(2n)
No Comments
6/15
QUESTION 3 Time Complexity of Searching a Linked List
Multiple Choice Easy Algorithms
Search
Correct Answer
QUESTION DESCRIPTION
Score 5
What is the time complexity to find an element in a linked list of length n?
CANDIDATE ANSWER
0(log2n)
0(n)
0(1)
0(n2)
No Comments
QUESTION DESCRIPTION
Score 5
What is the time complexity of finding an element in a binary search tree with n elements?
CANDIDATE ANSWER
0(1)
0(log2 n)
0(n)
0(n log2 n)
No Comments
Problem Solving
Correct Answer
QUESTION DESCRIPTION
Score 75
The number of goals achieved by two football teams in matches in a league is given in the form of two
lists. For each match of team B, compute the total number of matches of team A where team A has scored
less than or equal to the number of goals scored by team B in that match.
Example
teamA = [1, 2, 3]
teamB = [2, 4]
Team A has played three matches and has scored teamA = [1, 2, 3] goals in each match respectively.
7/15
Team B has played two matches and has scored teamB = [2, 4] goals in each match respectively. For 2
goals scored by team B in its first match, team A has 2 matches with scores 1 and 2. For 4 goals scored by
team B in its second match, team A has 3 matches with scores 1, 2 and 3. Hence, the answer is [2, 3].
Function Description
Constraints
2 ≤ n, m ≤ 105
1 ≤ teamA[j] ≤ 109, where 0 ≤ j < n.
1 ≤ teamB[i] ≤ 109, where 0 ≤ i < m.
Input from stdin will be processed as follows and passed to the function.
Sample Case 0
Sample Input 0
STDIN Function
----- --------
4 → teamA[] size n = 4
1 → teamA = [1, 4, 2, 4]
4
2
4
2 → teamB[] size m = 2
3 → teamB = [3, 5]
5
Sample Output 0
2
4
Explanation 0
Given values are n = 4, teamA = [1, 4, 2, 4], m = 2, and teamB = [3, 5].
1. For teamB[0] = 3, we have 2 elements in teamA (teamA[0] = 1 and teamA[2] = 2) that are ≤
teamB[0].
2. For teamB[1] = 5, we have 4 elements in teamA (teamA[0] = 1, teamA[1] = 4, teamA[2] = 2, and
teamA[3] = 4) that are ≤ teamB[1].
Thus, the function returns the array [2, 4] as the answer.
Sample Case 1
Sample Input 1
STDIN Function
8/15
STDIN Function
----- --------
5 → teamA[] size n = 5
2 → teamA = [2, 10, 5, 4, 8]
10
5
4
8
4 → teamB[] size m = 4
3 → teamB = [3, 1, 7, 8]
1
7
8
Sample Output 1
1
0
3
4
Explanation 1
Given values are n = 5, teamA = [2, 10, 5, 4, 8], m = 4, and teamB = [3, 1, 7, 8].
1. For teamB[0] = 3, we have 1 element in teamA (teamA[0] = 2) that is ≤ teamB[0].
2. For teamB[1] = 1, there are 0 elements in teamA that are ≤ teamB[1].
3. For teamB[2] = 7, we have 3 elements in teamA (teamA[0] = 2, teamA[2] = 5, and teamA[3] = 4) that
are ≤ teamB[2].
4. For teamB[3] = 8, we have 4 elements in teamA (teamA[0] = 2, teamA[2] = 5, teamA[3] = 4, and
teamA[4] = 8) that are ≤ teamB[3].
Thus, the function returns the array [1, 0, 3, 4] as the answer.
INTERVIEWER GUIDELINES
Hint 1
Notice that since for every element x in teamB, you need to find out number of elements not greater
than x in teamA, the order of elements of teamA does not need to be maintained. Sorting of elements
in teamA might help.
Hint 2
To find the number of elements in teamA that are less than or equal to x, you can do binary search.
Solution
Complexity Analysis
Time Complexity - O(m log n) where n is the number of elements in teamA and m is the number of
elements in teamB
For each element in teamB, do a binary search in an array of length n, and the time complexity of
binary search is O(logn). Therefore, the overall time complexity is O(m log n)
Space Complexity - O(m).
Since you return an array of m integers, the space complexity is O(m).
CANDIDATE ANSWER
1 /*
2 * Complete the 'counts' function below.
3 *
4 * The function is expected to return an INTEGER_ARRAY.
5 * The function accepts following parameters:
6 * 1. INTEGER_ARRAY teamA
7 * 2. INTEGER_ARRAY teamB
8 */
9
10 function counts(teamA, teamB) {
11 // Write your code here
12 function findIndexInA(num) {
13 let start = 0, end = teamA.length - 1
14
15 if (num >= teamA[end]) return teamA.length
16 if (num < teamA[start]) return 0
17
18 let ans = end
19 let mid = 0
20 while (start <= end) {
21 mid = start + Math.floor((end - start) / 2)
22 if (num >= teamA[mid]) {
23 start = mid + 1
24 ans = start
25 } else {
26 end = mid - 1
27 }
28 }
29 return ans
30 }
31
32 const results = []
10/15
33 teamA.sort((a, b) => a - b) // Onlogn
34 for (let b of teamB) {
35 // find pos of b in A -> result = index of b
36 results.push(findIndexInA(b)) // Ologn
37 }
38 // O logn (m + n)
39 return results
40 }
No Comments
Given a hashmap implemented by chaining technique with 5 buckets and an perfect hash function, what is
Score 5
probability of 0 collision after inserting 3 keys?
CANDIDATE ANSWER
0.48
3/5
No Comments
11/15
QUESTION 7 Quicksort
Multiple Choice
Correct Answer
QUESTION DESCRIPTION
CANDIDATE ANSWER
Odd levels of recursions pick the smallest element as pivot and even
levels split evently
No Comments
QUESTION 8 BFS
Multiple Choice
Given an undirected graph G with edges: (a, b), (a, e), (a, c), (b, e), (e, d), (d, f), then possible node visiting
Score 5
sequence(s) of BFS is/are: (can select multiple answers)
CANDIDATE ANSWER
abecdf
aecbfd
acebdf
fdecba
No Comments
12/15
QUESTION 9 Guess D.S
Multiple Choice
Correct Answer
QUESTION DESCRIPTION
A data structure is required for storing a set of integers such that each of the following operations can be
Score 5
done in O(log n) time, where n is the number of elements in the set
CANDIDATE ANSWER
No Comments
QUESTION 10 OS
Multiple Choice
Consider an enhancement to a processor which executes 10 times faster than the original but only applies
Score 5
to 40% of the workload.
What is the overall speedup when the improvement is incorporated?
CANDIDATE ANSWER
1.51
2.27
1.56
2.17
No Comments
13/15
QUESTION 11 D.S
Multiple Choice
Correct Answer
QUESTION DESCRIPTION
Which of the following statements is/are true? (Can choose multiple answers)
Score 5
CANDIDATE ANSWER
A dynamic array can allow append on tail with amortized O(1) time
No Comments
QUESTION 12 Replication
Multiple Choice
Correct Answer
QUESTION DESCRIPTION
Replication is a concept of storing multiple copies of the same data. Which of the following are true?
Score 5
Pick ONE OR MORE options
CANDIDATE ANSWER
No Comments
14/15
QUESTION 13 Message Queue
Multiple Choice
Correct Answer
QUESTION DESCRIPTION
In a modern distributed system, message queues are important components that provide communication
Score 3.33
between and coordination of the parts of the system.
Which of the following are true? Pick ONE OR MORE options
CANDIDATE ANSWER
No Comments
15/15