
PAST QUESTIONS
CLICK THE BUTTON BELOW TO BE DIRECTED TO THE HACKERRANK PLATFORM.
There you can attempt our Virtana Code Jam (Feb 2020) questions with similar constraints to our competition. We encourage you to attempt before viewing answers.
This is a great way to practice for future Code Jam competitions.
Round 1 - Q1 - Validate UTF-8 Character
UTF-8 is a character encoding that maps each symbol to one, two, three, or four bytes.
For example, the Euro sign, €, corresponds to the three bytes 11100010 10000010 10101100.
The rules for mapping characters are as follows: For a single-byte character, the first bit must be zero. For an n-byte character, the first byte starts with n ones and a zero. The other n - 1 bytes all start with 10. Visually, this can be represented as follows:
Bytes | Byte format ---------|------------------------------------- 1 | 0xxxxxxx 2 | 110xxxxx 10xxxxxx 3 | 1110xxxx 10xxxxxx 10xxxxxx 4 | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
Problem Statement:
Write a program that takes in a list of integers representing byte values, and returns whether it is a valid UTF-8 encoding.
Input Format:
The first line of input represents the number of bytes, n, in the encoding. The second line represents the n byte values, separated by spaces.
Constraints:
None.
Output Format:
A lowercase string; “true” if the list is a valid UTF-8 encoding, “false” otherwise.
Tags ?
Sample Input:
0 (the Euro sign) 3 226 130 172
+ Solution to Round 1 Question 1
Round 1 - Q2 - Clock Angles
Given a clock time in hh:mm format, determine (rounded up to the nearest degree), the smaller angle between the hour and the minute hands.
Bonus: When, during the course of a day, will the angle be zero?
+ Solution to Round 1 Question 2
Round 2 - Q1 - Find the Nth row of Pascal’s Triangle
Pascal's Triangle is a triangular array on integers constructed with the following formula:
The 0th row consists of the number 1 .
For each subsequent row, each element is the sum of the numbers directly above it, on either side.
For example, here are the first few rows:
1 Row 0 1 1 Row 1 1 2 1 Row 2 1 3 3 1 Row 3 1 4 6 4 1 Row 4
Given an unsigned input, k, return the kth row of Pascal's Triangle. You are not required to generate the full triangle.
Bonus: Can you do this using only O(k) space?
Example: k = 5 Output: [1, 5, 10, 10, 5, 1]
+ Solution to Round 2 Question 1
Round 3 - Q1 - Jumping Problem
Starting from 0 on a number line, you would like to make a series of jumps that lead to the integer N.
On the ith jump, you may move exactly i places to the left or right.
Find the fewest number of jumps required to get from 0 to N.
Bonus: Output the path taken.