Twitter OA | 2022 Twitter Early Career Engineering Coding Challenge
5941

There were 4 questions and time given was 75 mins and on HackerRank Platform.

q1 : Birthday Card collection : Given nums and threshold d. Find the smallest set of numbers that add upto d and is not present in nums.
eg : nums : [ 2 , 3 , 5 ] , d = 7
output = [ 1 , 4 ]

Q2 : Disk Space Analysis : Given nums and segment x. Find for each segment of size x the minimum number and find the maximum of all these segments.
Eg : [ 8,2,4,6 ] , x = 2
output = max( [ 2 , 2 , 4 ] ) = 4

Q3 : Balancing Parantheses : Similar to this : https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/

Q4 : String Reduction : Given a string , reduce string such that all of its substrings are distinct.
Eg : s = "abab" substr = { a , b , ab , ba , aba , bab , abab }.
output : Delete one 'a' and one 'b' - > return 2

Was able to solve all the four.
This is how i solved the problems

1. Used a set + looped through d and append to result all the numbers not in the set -> O( d ) + set O(n)
2. Sliding window + dequeue O( n ) + O( x )
3. Usual parenthesis matching algorithm modification is enough -> O( n ) + Stack O(n) ( worst )
4. return len(string) - len( set( string ) ) -> one liner

Hope this helps !!!

Comments (7)