You are on page 1of 15

Orange  quockhanh.abc@gmail.

com

You can view this report online at : https://www.hackerrank.com/x/tests/1392011/candidates/41617247/report

Full Name: Quoc-Khanh Bui

Email: quockhanh.abc@gmail.com scored in Orange in 83 min 49


75%
Test Name: Orange sec on 28 Jun 2022 20:31:12
135/180 CST
Taken On: 28 Jun 2022 20:31:12 CST

Time Taken: 83 min 49 sec/ 90 min

Work Experience: 2 years

Invited by: quang

Invited on: 28 Jun 2022 19:32:31 CST

Skills Score: Problem Solving (Basic) 50/50

Problem Solving (Intermediate) 40/75

Tags Score: Algorithms 55/90

Arrays 40/75
Binary Search 40/75

Binary Search Trees 5/5


Data Structures 40/75

Easy 65/65

Medium 40/75
Problem Solving 95/130

Search 5/5
Strings 50/50

Trees 5/5

Recruiter/Team Comments:

No Comments.

Question Description Time Taken Score Status

Q1 Are they Pangrams  Coding 15 min 47 sec 50/ 50 


Q2 Complexity of the Code Snippet  Multiple Choice 3 min 41 sec 5/ 5 
Q3 Time Complexity of Searching a Linked List  Multiple Choice 17 sec 5/ 5 
Q4 Time Complexity of Searching a Binary Search Tree  Multiple Choice 17 sec 5/ 5 
Q5 Football Scores  Coding 45 min 25 sec 40/ 75 
Q6 Hash table collision probability  Multiple Choice 1 min 32 sec 0/ 5 
1/15
Q7 Quicksort  Multiple Choice 21 sec 5/ 5 
Q8 BFS  Multiple Choice 2 min 29 sec 5/ 5 
Q9 Guess D.S  Multiple Choice 3 min 58 sec 5/ 5 
Q10 OS  Multiple Choice 3 min 2 sec 5/ 5 
Q11 D.S  Multiple Choice 4 min 5/ 5 
Q12 Replication  Multiple Choice 1 min 18 sec 5/ 5 
Q13 Message Queue  Multiple Choice 1 min 25 sec 0/ 5 

QUESTION 1 Are they Pangrams 



Coding Easy Strings Problem Solving

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'.

Function Description Complete the function isPangram n the editor below.

isPangram has the following parameter(s):


string pangram[n]: an array of strings
Returns:
string: a string where each position represents the results of a test. Use '1' for true and '0' for false.

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 Format for Custom Testing

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'

Sample Case 1Sample Input 1

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

Time Complexity - O(n).


All characters of the string need to be checked if it is not a pangram.
Space Complexity - O(1) - Constant extra space is required.
Regardless of string size, only an additional 26 element array and a counter variable are required.

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 -

def containsChars(testString, universe):


# mark all as seen
seen = [1] * 26
# mark all characters in universe as unseen
# also, count unique characters
uc = 0
for c in universe:
idx = ord(c) - ord('a')
if seen[idx]:
uc += 1
seen[idx] = 0
# now do just as in the pangrams exercise
# but test against the unique count instead of 26
count = 0
for c in testString:
idx = ord(c) - ord('a')
4/15
if not c == ' ' and seen[idx] == 0:
count+= 1
seen[idx] = 1
if count == uc:
break
return True if count == uc else False

CANDIDATE ANSWER

Language used: Python 3

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 TOTAL_LETTER = 26
8
9 def isEnglishLetter(char: str) -> bool:
10 if char.lower() >= 'a' and char.lower() <= 'z':
11 return True
12 return False
13
14 def isPangram(pangram: [str]):
15 result = ''
16 for item in pangram:
17 uniqueChar = set([])
18 enough = False
19 for ch in item:
20 if isEnglishLetter(ch):
21 uniqueChar.add(ch)
22 if len(uniqueChar) == TOTAL_LETTER:
23 enough = True
24 break
25 if enough:
26 result += '1'
27 else:
28 result += '0'
29 return result
30
31
32

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

TestCase 0 Easy Sample case  Success 1 0.0478 sec 9.52 KB

TestCase 1 Easy Sample case  Success 1 0.0498 sec 9.54 KB

TestCase 2 Easy Sample case  Success 1.5 0.0506 sec 9.6 KB

TestCase 3 Easy Sample case  Success 1.5 0.056 sec 9.47 KB

TestCase 4 Easy Sample case  Success 5 0.0706 sec 9.55 KB

TestCase 5 Easy Hidden case  Success 5 0.1278 sec 9.73 KB

TestCase 6 Easy Hidden case  Success 5 0.0717 sec 9.89 KB

TestCase 7 Easy Hidden case  Success 5 0.0652 sec 9.64 KB

TestCase 8 Easy Hidden case  Success 5 0.0707 sec 9.7 KB

5/15
TestCase 9 Easy Hidden case  Success 5 0 0908 sec 10 8 KB
TestCase 9 Easy Hidden case  Success 5 0.0908 sec 10.8 KB

TestCase 10 Easy Hidden case  Success 5 0.1162 sec 10.7 KB

TestCase 11 Easy Hidden case  Success 5 0.0712 sec 10.8 KB

TestCase 12 Easy Hidden case  Success 5 0.0947 sec 10.5 KB

No Comments

QUESTION 2 Complexity of the Code Snippet 



Multiple Choice Algorithms Easy Problem Solving

Correct Answer
QUESTION DESCRIPTION

Consider the following code snippet:


Score 5

int a = 1;

while (a < n) {
a = a * 2;
}

What is the complexity of the above code snippet?

INTERVIEWER GUIDELINES

Task is reducing exponentially by an order of 2.

CANDIDATE ANSWER

Options: (Expected answer indicated with a tick)

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

Options: (Expected answer indicated with a tick)

0(log2n)

0(n)

0(1)

0(n2)

No Comments

QUESTION 4 Time Complexity of Searching a Binary Search Tree 



Multiple Choice Easy

Algorithms Trees Binary Search Trees


Correct Answer

QUESTION DESCRIPTION
Score 5
What is the time complexity of finding an element in a binary search tree with n elements?

CANDIDATE ANSWER

Options: (Expected answer indicated with a tick)

0(1)

0(log2 n)

0(n)

0(n log2 n)

No Comments

QUESTION 5 Football Scores 



Coding Data Structures Medium Binary Search Algorithms Arrays

Problem Solving
Correct Answer

QUESTION DESCRIPTION
Score 40
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

Complete the function counts in the editor below.

counts has the following parameter(s):


int teamA[n]: first array of positive integers
int teamB[m]: second array of positive integers
Return
int[m]: an array of m positive integers, one for each teamB[i] representing the total number of elements
from teamA[j] satisfying teamA[j] ≤ teamB[i] where 0 ≤ j < n and 0 ≤ i < m, in the given order.

Constraints
2 ≤ n, m ≤ 105
1 ≤ teamA[j] ≤ 109, where 0 ≤ j < n.
1 ≤ teamB[i] ≤ 109, where 0 ≤ i < m.

Input Format For Custom Testing

Input from stdin will be processed as follows and passed to the function.

The first line contains an integer n, the number of elements in teamA.


The next n lines each contain an integer describing teamA[j] where 0 ≤ j < n.
The next line contains an integer m, the number of elements in teamB.
The next m lines each contain an integer describing teamB[i] where 0 ≤ i < m.

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

Concepts covered: Binary Search


Optimal Solution:
Let's just consider array teamB to be a set of queries which ask us to find the number of integers in
teamA that are less than or equal to x. Notice that even after sorting the array teamA, the answer will
not change, so sort the array teamA. Now for each query x, we can find the first integer in teamA such
that it is greater than x using a binary search. The index of this integer gives the number of integers
that are less than or equal to x.

def counts(teamA, teamB):


ans = []
teamA.sort()
for score in teamB:
lo, hi = 0, len(teamA) - 1
while lo <= hi:
mid = (lo + hi) // 2
if teamA[mid] > score:
hi = mid - 1
else:
lo = mid + 1
ans.append(lo)
return ans
9/15
Brute Force Approach: Passes 8 of 13 test cases

def counts(teamA, teamB):


ans = []
for score in teamB:
cnt = 0
for i in teamA:
if i <= score:
cnt += 1
ans.append(cnt)
return ans

Error Handling: There are no edge cases in the problem.

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

Language used: Python 3

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 def counts(teamA, teamB):
10 # Write your code here
11 print(teamA, teamB)
12 MAX = max(teamA)
13 result = []
14 milestones = [0] * MAX
15 print("length: ", len(milestones))
16 for goal in teamA:
17 milestones[goal - 1] += 1
18 accumulative = 0
19 print(milestones)
20 prefixGoal = []
21 for milestone in milestones:
22 accumulative += milestone
23 prefixGoal.append(accumulative)
24 print(prefixGoal)
25 for goal in teamB:
26 if goal > MAX:
27 result.append(prefixGoal[-1])
28 else:
29 result.append(prefixGoal[goal - 1])
30 return result
31
10/15
32

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

TestCase 0 Easy Sample case  Success 1 0.063 sec 9.44 KB

TestCase 1 Easy Sample case  Success 1 0.0442 sec 9.5 KB

TestCase 2 Medium Sample case  Success 1 0.0749 sec 9.34 KB

TestCase 3 Medium Sample case  Success 8 0.1364 sec 13.9 KB

TestCase 4 Medium Sample case  Success 8 0.4729 sec 63.8 KB

TestCase 5 Medium Hidden case  Success 7 0.2953 sec 68.7 KB

TestCase 6 Medium Hidden case  Success 7 0.428 sec 68.6 KB

TestCase 7 Medium Hidden case  Success 7 0.4872 sec 69 KB

TestCase 8 Hard Hidden case  Runtime Error 0 0.3435 sec 19.6 KB

TestCase 9 Hard Hidden case  Runtime Error 0 0.5129 sec 19.5 KB

Testcase 10 Easy Hidden case  Runtime Error 0 2.6958 sec 781 KB

Testcase 11 Hard Hidden case  Runtime Error 0 0.5321 sec 19.6 KB

Testcase 12 Easy Hidden case  Runtime Error 0 0.2913 sec 19.6 KB

No Comments

QUESTION 6 Hash table collision probability 



Multiple Choice

Not Submitted QUESTION DESCRIPTION

Given a hashmap implemented by chaining technique with 5 buckets and an perfect hash function, what is
Score 0
probability of 0 collision after inserting 3 keys?

CANDIDATE ANSWER

 This candidate has not answered this question.

No Comments

11/15
QUESTION 7 Quicksort 

Multiple Choice

Correct Answer
QUESTION DESCRIPTION

In Quicksort, which of following scenarios will have a runtime of O(n^2)


Score 5

CANDIDATE ANSWER

Options: (Expected answer indicated with a tick)

The pivot is always the smallest element in the partition

The pivot always produces a 9 to 1 split

The pivot is always the median in the partition

Odd levels of recursions pick the smallest element as pivot and even
levels split evently

No Comments

QUESTION 8 BFS 

Multiple Choice

Correct Answer QUESTION DESCRIPTION

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

Options: (Expected answer indicated with a tick)

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

- Deletion of the smallest element.


- Insertion of an element if it is not already present in the set.

CANDIDATE ANSWER

Options: (Expected answer indicated with a tick)

A heap can be used but not a balanced binary search tree

A balanced binary search tree can be used but not a heap

Neither balanced binary search tree nor heap can be used

Both balanced binary search tree and heap can be used

No Comments

QUESTION 10 OS 

Multiple Choice

Correct Answer QUESTION DESCRIPTION

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

Options: (Expected answer indicated with a tick)

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

Options: (Expected answer indicated with a tick)

A heap is a balanced binary search tree that allows lookup by key in


O(log(n))

A sorted doubly-linked list can allow binary search in average O(log(n))


time

A dynamic array can allow append on tail with amortized O(1) time

Insert and Pop min in a Min Heap take 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

Options: (Expected answer indicated with a tick)

Replication improves the reliability of the system

Replication does not affect latency.

Replication affects consistency negatively

Replication improves consistency

No Comments

14/15
QUESTION 13 Message Queue 

Multiple Choice

Wrong Answer
QUESTION DESCRIPTION

In a modern distributed system, message queues are important components that provide communication
Score 0
between and coordination of the parts of the system.
Which of the following are true? Pick ONE OR MORE options

CANDIDATE ANSWER

Options: (Expected answer indicated with a tick)

Message queues increase the complexity of the system architecture

Message queues increase the reliability of the system

Message queues, in general, decrease the overall performance of the


system

Message queues make system more decouple

No Comments

PDF generated at: 28 Jun 2022 13:56:43 UTC

15/15

You might also like