You are on page 1of 15

Orange  ngviethoang0212@gmail.

com

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

Full Name: Viet Hoang

Email: ngviethoang0212@gmail.com scored in Orange in 89 min 51


99.1%
Test Name: Orange sec on 28 Jun 2022 20:17:27
178/180 CST
Taken On: 28 Jun 2022 20:17:27 CST

Time Taken: 89 min 51 sec/ 90 min

Work Experience: 3 years

Invited by: quang

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

Skills Score: Problem Solving (Basic) 50/50

Problem Solving (Intermediate) 75/75

Tags Score: Algorithms 90/90

Arrays 75/75
Binary Search 75/75

Binary Search Trees 5/5


Data Structures 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.

Question Description Time Taken Score Status

Q1 Are they Pangrams  Coding 9 min 3 sec 50/ 50 


Q2 Complexity of the Code Snippet  Multiple Choice 2 min 46 sec 5/ 5 
Q3 Time Complexity of Searching a Linked List  Multiple Choice 15 sec 5/ 5 
Q4 Time Complexity of Searching a Binary Search Tree  Multiple Choice 13 sec 5/ 5 
Q5 Football Scores  Coding 51 min 48 sec 75/ 75 
Q6 Hash table collision probability  Multiple Choice 6 min 21 sec 5/ 5 
1/15
Q7 Quicksort  Multiple Choice 4 min 21 sec 5/ 5 
Q8 BFS  Multiple Choice 1 min 58 sec 5/ 5 
Q9 Guess D.S  Multiple Choice 1 min 43 sec 5/ 5 
Q10 OS  Multiple Choice 4 min 3 sec 5/ 5 
Q11 D.S  Multiple Choice 2 min 4 sec 5/ 5 
Q12 Replication  Multiple Choice 3 min 49 sec 5/ 5 
Q13 Message Queue  Multiple Choice 1 min 25 sec 3.33/ 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: JavaScript (Node.js)

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

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

TestCase 0 Easy Sample case  Success 1 0.1048 sec 31.1 KB

TestCase 1 Easy Sample case  Success 1 0.045 sec 31.1 KB

TestCase 2 Easy Sample case  Success 1.5 0.0723 sec 31.2 KB

TestCase 3 Easy Sample case  Success 1.5 0.0476 sec 30.8 KB

TestCase 4 Easy Sample case  Success 5 0.049 sec 33.6 KB

TestCase 5 Easy Hidden case  Success 5 0.1162 sec 34.5 KB

TestCase 6 Easy Hidden case  Success 5 0.0622 sec 34.8 KB

TestCase 7 Easy Hidden case  Success 5 0.0979 sec 34.3 KB

TestCase 8 Easy Hidden case  Success 5 0.0722 sec 33.6 KB

TestCase 9 Easy Hidden case  Success 5 0.1488 sec 37.5 KB

5/15 
TestCase 10 Easy Hidden case  Success 5 0.0797 sec 37.4 KB

TestCase 11 Easy Hidden case  Success 5 0.0948 sec 36.1 KB

TestCase 12 Easy Hidden case  Success 5 0.0941 sec 36.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 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

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: JavaScript (Node.js)

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 }

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

TestCase 0 Easy Sample case  Success 1 0.0759 sec 30.9 KB

TestCase 1 Easy Sample case  Success 1 0.1071 sec 31.1 KB

TestCase 2 Medium Sample case  Success 1 0.0718 sec 31 KB

TestCase 3 Medium Sample case  Success 8 0.0849 sec 31.5 KB

TestCase 4 Medium Sample case  Success 8 0.071 sec 31.2 KB

TestCase 5 Medium Hidden case  Success 7 0.0768 sec 31.2 KB

TestCase 6 Medium Hidden case  Success 7 0.0489 sec 31.3 KB

TestCase 7 Medium Hidden case  Success 7 0.0893 sec 31 KB

TestCase 8 Hard Hidden case  Success 6 0.1635 sec 61.5 KB

TestCase 9 Hard Hidden case  Success 5 0.1912 sec 64 KB

Testcase 10 Easy Hidden case  Success 8 0.1299 sec 61.8 KB

Testcase 11 Hard Hidden case  Success 8 0.2154 sec 61.2 KB

Testcase 12 Easy Hidden case  Success 8 0.5004 sec 61.4 KB

No Comments

QUESTION 6 Hash table collision probability 



Multiple Choice

Correct Answer QUESTION DESCRIPTION

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

Options: (Expected answer indicated with a tick)

0.48

3/5

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

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

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:49:45 UTC

15/15

You might also like