### Introduction

HackWithInfy is a national level Hackathon competition arranged by Infosys every year.

Since it is a national level hackathon, there are generally two rounds before the actual on-site hackathon event which happens on their Pune campus.

In 2019, around `1,20,000`

students participated from all over India.

Let's now get to the part for which you are here exactly, the questions of Round 1 in HackWithInfy 2019.

### Questions

The format for these online rounds is 3 questions and 3 hours. You can spend time on any question you like and you are allowed to switch between questions. The platform used for these competitions is Hackerrank

Kindly note that these are the questions that were in my set. There were different sets with different kinds of questions. However, I believe the question might be different however the difficulty is moreover the same.

### Question 1 - Slowest Key Press

#### Problem Statement

Alex wants to be a faster typist and is taking a typing test to find out which key takes the longest time to press.

Given the results of the test, determine which key takes the longest to press.

For example, given keyTimes =[[0, 2], [1, 5], [0, 9], [2, 15]]. Interpret each keyTimes[i][0] as an encoded character in the range ascii[a-z] where a = 0, b = 1,...z = 25.

The second element, represents the time the key is pressed since the start of the test.

In the example, keys pressed, in order are abac at times 2, 5, 9, 15. From the start time, it took 2 - 0 = 2 to press the first key, 5 - 2 = 3 to press the second, and so on.

The longest time it took to press a key was key 2, or 'c', at 15 - 9 = 6.

#### Function Description

Complete the function slowestKey in the editor below. The function must return a character, the slowest key that Alex presses.

slowestKey has the following parameter(s):

keyTimes[keyTimes[O],... keyTimes[n-1]]: an array of two integers: The character Alex pressed (encoded) and the time at which it was pressed

#### Constraints

• 1 <= n <= 10^5

• 0 <= keyTimes[i][0] <= 25 (0 <= i <= n)

• 1 <= keyTimes[i][1] <= 10^8 (0 <= i <= n)

• It is guaranteed that there will only be one key with the worst time. Input Format For Custom Testing

#### Sample Input

```
3
2
0 2
1 3
0 7
```

#### Sample Output

`a`

#### Explanation:

The time taken to press 'a' in the worst case is 7 - 3 = 4. To press 'b' the worst case is 3 - 2 = 1. Alex performed worst on 'a'.

### Question 2 - Rock Paper Scissor

#### Problem Statement

In a Rock Paper Scissor tournament, the contestants stand in a straight line. Each pair of consecutive players compete in a round. If there is an odd number of players, the last one in the line qualifies for the next round without playing.

For each game, each player indicates either a rock, paper or scissors denoted 'R', 'P' or 'S' respectively. Outcomes are as follows:

• paper beats rock, P > R

• scissors beat paper, S > P

• rock beats scissors, R > S

After each round, the winners remain and the losers are out of the competition. In case of a tie, both players lose. A player would like to win the competition and has one advantage: the knowledge that each other player uses only one type of hand formation in all the rounds of the tournament. Determine how many times the player will have to change the hand formation in order to win the competition.

For example, the number of players, n = 3, and the player of interest, POI, is standing at position given by a = 2 (0-based index). The hand formations used by other players are given by formations = "PS" with length n - 1 = 2. In the first round, scissors (S) beats paper (P). POI must then beat the winner of round one who always chooses scissors (S). POI will choose rock (R) and win the tournament after having chosen only one hand formation, hence the answer is 0.

#### Function Description

Complete the function handFormationChange in the editor below. The function must return an integer, the number of times the POI needs to change hand formation.

handFormationChange has the following parameter(s): n: an integer, the number of players in the tournament a: an inteqer, the POI's position in the line, 0-indexed

#### Constraints

• 2 <= n <= 10^5

• 0 <= a <= n

• formations[i] belongs to {'R', 'S', 'P'} (0 <= i < n-1)

#### Sample Input

```
4
1
PRS
```

#### Sample Output

`1`

#### Explanation:

In the first round, POI is at position 1 and must beat paper at position O by choosing S, scissors. For the second pair, rock beats scissors. Now the POI must choose paper to beat rock in round two. It takes one change of formation to win the tournament.

### Question 3 - Dangerous Script

#### Problem Statement

If you've ever looked at an assembly language dump of an executable file, you know that commands come in the form of hexadecimal digits that are grouped by the processor into instructions. It is important that the parsing be done correctly or code will not be executed as expected. Wrong parsing is the basis for Return Oriented Programming, a method of causing mahem.

You have developed a program in a new scripting language. Of course, it requires accurate parsing in order to perform as expeced, and it is very cryptic. You want to determine how many valid commands can be made out of your lines of script. To do this, you count all of the substrings that make up a valid command. Each of the valid commands will be in the following format:

• The first letter is a lowercase English letter.

• Next, it contains a sequence of zero or more of the following characters: lowercase English letters, digits, and colons.

• Next, it contains a forward slash '/'.

• Next, it contains a sequence of one or more of the following characters: lowercase English letters and digits.

• Next, it contains a backward slash '\'.

• Next, it contains a sequence of one or more lowercase English letters.

Given some string, s, we define the following: • s[i..j] is a substring consisting of all the characters in the inclusive range between index i and index j.

• Two substrings, s[i[1]..j[1]] and s[i[2]..j[2]] are said to be distinct if either i[1] != i[2] or j[1] != j[2].

For example, your command line is abc:/b1c\xy.

Valid command substrings are:

abc:/b1c\xy

bc:/b1c\xy

c:/b1c\xy

abc:/b1c\x

bc:/b1c\x

c:/b1c\x

There are six valid commands that may be parsed from that one command string.

#### Function Description

Complete the function commandCount in the editor below. The function must return an array of integers, each representing the number of valid command strings in commands[i].

commandCount has the following parameter(s): commands[commands[0],...commands[n-l]]: an array of strings

#### Constraints

• 1 <= n <= 50

• Each character of commands[i] belongs to [a-z, 0-9, /, \, :]

• Each |commands[i]| <= 5 * 10^5.

#### Sample Input

```
6
w\\//a/b
w\\//a\b
w\\/a\b
w:://a\b
w::/a\b
w:/a\bc::/12\xyz
```

#### Sample Output

```
0
0
0
0
1
8
```

#### Explanation:

Let's call our return array ret.

We fill ret as follows:

• commands[0] = "w\//a/b" has no valid command substring, so ret[0] = 0.

• commands[1] = "w\//a\b" has no valid command substring, so ret[1] = 0.

• commands[2] = "w\/a\b" has no valid command substring, so ret[2] = 0.

• commands[3] = "w:://a\b" has no valid command substring, so ret[3] = 0.

• commands[3] = "w::/a\b" has one valid command substring, commands[O..6] = "w::/a\b" so ret[4] = 1

• commands[5] = "w:/a\bc::/12\xyz" has the following eight valid command substrings:

- commands[0..5] = w:/a\b
- commands[O..6] = w:/a\bc
- commands[5..13] = bc::/12\x
- commands[5..14] = bc::/12\xy
- commands[5..15] = bc::/12\xyz
- commands[6..13] = c::/12\x
- commands[6..14] = c::/12\xy
- commands[6..15] = c::/12\xyz

This means ret[5] = 8

We then return ret = [0, 0, 0, 0, 1, 8].

### My Experience

I'm pretty sure 80% of all the readers didn't complete reading the last question. Well, guess what, so didn't I!

Tbh, during the competition, I didn't even get the time to get started with the third question. I was able to solve the first one with all the 14 test cases cleared.

I struggled on the second one a lot. I was able to come up with a brute force solution but I could only get 5-6 test cases from a total of 14.

After handling a few edge cases I was able to get a total of 8 test cases on the second question. However, these 8 questions were from Test cases 0 - 7.

Usually, the later test cases hold major points as they test the boundary values mentioned in the constraints of each question (for example, n can be up to 10^8).

So the eight cases that I was able to solve didn't account many scores compared to those end test cases.

So I can conclude that I was able to solve less the 1.5 questions in round 1 of HackWithInfy 2019.

### Conclusion

Well, some of you might be thinking that he was able to solve just 1 question completely and another one partially, so that is probably an end for him.

Nope, That's not quite right. The result from Round 1 was that I was selected for Round 2 as well. This means from 1,20,000 students, I was among the top 7,500 students who were eligible for Round 2.

Why I am telling you this??

Because I want you to understand that if you are feeling that you are not cut for such a competition then stop that feeling right there. The goal is not to solve all three questions. You just have to make sure that you have scored better than the minimum required score, which in my case was 1.5.

One friend of mine was able to solve 1 question completely with all test cases and he also got selected for Round 2.

So many times not even the number of questions is the only criterion but the difficulty level of the question which you have got in your set.

With this, I would like to conclude this post and wish everyone good luck who are appearing for the competition soon.

See you in the Round 2 experience blog 👋