Difficulty: Medium Asked in: Amazon, Google Understanding The Problem Problem Description There are N gas stations along a circular route, where the amount of gas at station i is arr[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i toContinue reading… Gas Station Problem
Category: Placements
Monty Hall Puzzle
You’re on a game show and there are three doors in front of you. The host, Monty Hall, says, “Behind one door is a brand new car. Behind the other two doors are goats. Pick a door!” You think, “Well,Continue reading… Monty Hall Puzzle
Number of comparisons to find second minimum element in an Array
Given an array of numbers, we need to find the second min element with optimal number of comparisons. Let’s compare two elements (side by side) and get next set of min element list. Recursively, we end up with lowest numberContinue reading… Number of comparisons to find second minimum element in an Array
Base64 Encoding and Decoding in C
Base64 is a method of encoding arbitrary data as plain ASCII text. It is one of the techniques employed by the MIME standard to send data other than plain text. Base64 encoding takes three bytes, each consisting of eight bits,Continue reading… Base64 Encoding and Decoding in C
The Greedy Pirates! (Solution)
For Question The idea is to reduce the number of participants (greedy pirates) and see what happens in that case and start reasoning based on that. One more thing to note here is that a pirate would accept a proposalContinue reading… The Greedy Pirates! (Solution)
The Greedy Pirates!
There are 5 pirates, all of them being equally greedy. They have varied number of years of experience. Say for convenience sake 5, 4, 3, 2 and 1. They find a booty of 1000 gold coins which they want toContinue reading… The Greedy Pirates!
5 cards game … (Solution)
For Question Since there are 5 cards, at least two will have to be of same suite. So I keep one of them and pass the other one as the first card. This way the second guy will know theContinue reading… 5 cards game … (Solution)
5 cards game …
Two prisoners were sentenced to death by King Xuan of Zhou and were kept in two different inaccessible cells. They were to be put to the gallows the day after. However, King Xuan wanted to give them a last chance.Continue reading… 5 cards game …
Memory efficient doubly linked list
Linux Journal has an article in the January 2005 issue that introduces a doubly linked list that is designed for memory efficiency. Typically elements in doubly linked list implementations consist of a pointer to the data, a pointer to theContinue reading… Memory efficient doubly linked list
She-Ra and He-Man are twins; She-Ra is the OLDER twin. Assume they were born immediately after each other, an infinitesimally small – but nonzero – amount of time apart. During one year in the course of their lives, She-Ra celebrates her birthday two days AFTER He-Man does. How is this possible?
She-Ra and He-Man are twins; She-Ra is the OLDER twin. Assume they were born immediately after each other, an infinitesimally small – but nonzero – amount of time apart. During one year in the course of their lives, She-Ra celebratesContinue reading… She-Ra and He-Man are twins; She-Ra is the OLDER twin. Assume they were born immediately after each other, an infinitesimally small – but nonzero – amount of time apart. During one year in the course of their lives, She-Ra celebrates her birthday two days AFTER He-Man does. How is this possible?