There are a number of plants in a garden. Each of these plants has been treated with some amount of pesticide. After each day, if any plant has more pesticide than the plant on its left, being weaker than the left one, it dies. You are given the initial values of the pesticide in each of the plants. Print the number of days after which no plant dies, i.e. the time after which there are no plants...

## The problem of “Arrays: Left Rotation” – C Source code

A left rotation operation on an array shifts each of the array’s elements 1 unit to the left. For example, if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,5,1,2]. Given an array a of n integers and a number, d, perform d left rotations on the array. Return the updated array to be printed as a single line of space-separated integers. More information...

## The problem of “New Year Chaos” – C Source code

It’s New Year’s Day and everyone’s in line for the Wonderland rollercoaster ride! There are a number of people queued up, and each person wears a sticker indicating their initial position in the queue. Initial positions increment by 1 from 1 at the front of the line to n at the back. Any person in the queue can bribe the person directly in front of them to swap positions. If two...

## The problem of “Castle on the Grid” – C++ Source code

You are given a square grid with some cells open (.) and some blocked (X). Your playing piece can move along any row or column until it reaches the edge of the grid or a blocked cell. Given a grid, a start and an end position, determine the number of moves it will take to get to the end position. For example, you are given a grid with sides n=3 described as follows:. . .. X .. . . Your starting...

## The problem of “Repeated String” – C Source code

Lilah has a string, s , of lowercase English letters that she repeated infinitely many times. Given an integer, n, find and print the number of letter a‘s in the first n letters of Lilah’s infinite string. For example, if the string s=’abcac’ and n=10, the substring we consider is ‘abcacabcac’ , the first 10 characters of her infinite string. There are...

## The problem of “Sock Merchant” – C Source code

John works at a clothing store. He has a large pile of socks that he must pair by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. For example, there are socks n=7 with colors ar=[1,2,1,2,1,3,2] . There is one pair of color and one of color . There are three odd socks left, one of each color. The...

## The problem of “Counting Valleys” – C Source code

Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike he took exactly n steps. For every step he took, he noted if it was an U uphill, , or a D downhill, step. Gary’s hikes start and end at sea level and each step up or down represents a unit change in altitude. We define the following terms: A mountain is a...

## The problem of “Hash Tables: Ransom Notes” – C Source code

Harold is a kidnapper who wrote a ransom note, but now he is worried it will be traced back to him through his handwriting. He found a magazine and wants to know if he can cut out whole words from it and use them to create an untraceable replica of his ransom note. The words in his note are case-sensitive and he must use only whole words available in the magazine. He cannot use substrings or...