Short Problem Definition: A jail has N prisoners, and each prisoner has a unique id number,S , ranging from 1 to N. There are M sweets that must be distributed to the prisoners. But wait—there’s a catch—the very last sweet S is poisoned! Can you find and print the ID number of the last prisoner to receive a sweet so he can be warned? Link Save the Prisoner! Complexity: time complexity is O(1)...

## HackerRank ‘Jumping on the Clouds’ Solution

Short Problem Definition: Emma is playing a new mobile game involving clouds numbered from 1 to n. There are two types of clouds, ordinary clouds and thunderclouds. The game ends if Emma jumps onto a thundercloud, but if she reaches the last cloud, she wins the game! Link Jumping on the Clouds Complexity: time complexity is O(N) space complexity is O(N) Execution: Theoretically your solution can...

## HackerRank ‘Kangaroo’ Solution

Short Problem Definition: There are two kangaroos on an x-axis ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location x1 and moves at a rate of v1 meters per jump. The second kangaroo starts at location x2 and moves at a rate of v2 meters per jump. Given the starting locations and movement rates for each kangaroo, can you determine if...

## HackerRank ‘Flatland Space Station’ Solution

Short Problem Definition: For each city, determine its distance to the nearest space station and print the maximum of these distances. Link Flatland Space Station Complexity: time complexity is O(N) space complexity is O(N) Execution: This is a two pass algorithm. First, measure the distance to the last station on the left. And on the second pass measure the distance to the nearest station on the...

## HackerRank ‘Circular Array Rotation’ Solution

Short Problem Definition: John Watson performs an operation called a right circular rotation on an array of integers. Link Circular Array Rotation Complexity: time complexity is O(Q) space complexity is O(1) Execution: Calculate the offset for every query. Watch out for index overflows and negative modulo. Solution: [rust]use std::io; fn get_number() -> u32 { let mut line = String::new();...

## HackerRank ‘Compare Triplets’ Solution

Short Problem Definition: Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty. Link Compare Triplets Complexity: time complexity is O(1) space complexity is O(1) Execution: This is a warmup. Follow specification. Solution: [rust]use...