It was a proctored test on HackerRank. Webcam and mic need to be ON, and screen activities to be recorded by the system.
Duration = 60 minutes
Number of problems = 2
Both were very trivial Leetcode Easy type problems - took me just 13 minutes to solve both and get all tests (including ALL hidden tests) passing in first attempt itself.
UPDATE : Within minutes of this test completion, I received a template rejection email, despite all tests passing for my submission, and my webcam being on, no other tabs being open.
Looks like they want candidates who solve such trivial problems in 55+ minutes. Perhaps my speed led to my rejection - whatever ! 🙂 🙂
1. Given an array of strings. For each string, return the least number of characters to be modified so that there are NO consecutive identical characters in any string. All strings are non-empty and contain only lowercase English letters a-z.
Example : ab - 0 changes needed as there are no two identical consecutive characters in this string
aaa - change the middle a to something else - so just 1 modification needed
aaaab - change either first and third 'a' to something else, or else change 2nd and 4th 'a' to something else - 2 modifications needed
aaacc - change middle 'a' to something else and change one of the 'c' to something else - so just 2 modifications needed
aaaaabbbcc - change 2nd and 4th 'a', change middle 'b' and change any one of the 'c' - total 4 modifications needed
So, for input as [ab, aaa, aaab, aaacc, aaaaabbbcc], expected output is [0, 1, 2, 2, 4]
Outline of solution : For each string, check how many chains are there. A chain is a sequence of at least 2 identical consecutive characters.
For the string aaaaabbbcc, there are these chains - aaaaa, bbb and cc
Number of replacements = sum of (chainLength / 2) [integer division]
For abcd, there are 4 chains - a, b, c, d - each of length 1
Easily passed all tests
Time complexity = O(sum of all string lengths)
Space complexity = O(number of strings)
===============================================
2. Given an array of integers. You take an integer k, and go on adding the elements of the array consecutively.
After each addition, the sum must be at least +1. Find least possible value of k satisfying this condition.
Example - take this array A = [2, -4, 3, 1]
Suppose k = 3
3 + A[0] = 3 + 2 = 5
5 + A[1] = 5 +(-4) = 1
1 + A[2] = 1 + 3 = 4
4 + A[3] = 4 + 1 = 5
For k = 3, each sum is at least +1. No value of k smaller than 3 will satisfy this condition.
So, answer is k = 3
Outline of solution:
min = +INFINITY
sum = 0
for each x in array
sum = sum + x
min = least of sum and existing min
Answer is (1 - min).
Time complexity = O(array size)
Space complexity = O(1)