The puzzles tag is for discussing algorithms and design approaches for solving programming puzzles. Puzzle competitions or contests should be asked at Programming Puzzles & Code Golf.
Questions tagged [puzzles]
19 questions
167
votes
1 answer
Where can I find programming puzzles and challenges?
I'm trying to find places where I can hone my craft outside the context of school or work. Are there places online, or books available, where I can access lists of programming puzzles or challenges?

cmcculloh
- 1,025
- 3
- 9
- 10
91
votes
15 answers
Tricky logic puzzles - Are they really useful in assessing programming skills?
In the last interview I attended, I was asked to solve a puzzle where I was expected to measure exactly blah liters of water given two buckets with capacities - blah and blah liters respectively. I was unable to solve the puzzle in given time (~5…

missingfaktor
- 3,906
- 1
- 24
- 31
53
votes
11 answers
Get 100 highest numbers from an infinite list
One of my friend was asked this interview question -
"There is a constant flow of numbers coming in from some infinite list
of numbers out of which you need to maintain a datastructure as to
return the top 100 highest numbers at any given point…

Sachin Shanbhag
- 543
- 1
- 4
- 7
30
votes
5 answers
Champaign Fountain Puzzle
Empty glasses of water are arranged in the following order:
When you pour liquid into the 1st glass if it's full, then the extra liquid would be flown into the glasses 2 and 3 in equal quantities. When glass 2 is full, the extra liquid would be…

Vrashabh Irde
- 442
- 6
- 13
10
votes
4 answers
Are Quines useful as anything more than a programming puzzle?
Quines, which are programs that generate their own code as part or all of their output are a neat idea for a programming puzzle. However, do they have any use beyond that?
user28988
10
votes
7 answers
N queens, X by Y board decision problem interview question
I was asked the following question in an interview today and I've been thinking about it ever since. I was not able to answer it and haven't been able to find a solution online.
Given a chess board with dimensions X by Y and N queens, determine…

Interviewee
- 111
- 1
- 4
4
votes
5 answers
sets of numbers that sum to a certain number?
I was asked this in an interview, and I'm not sure what the answer is or how to approach the problem.
Find a pair of numbers that sum up to zero (or any other number), then find three (and then four) numbers that sum up to zero.

user20598
- 141
- 1
- 2
3
votes
3 answers
Find a line that is closest to scattered points
I came across the below interview question on Glassdoor:
A scatter graph of points on a page, draw a horizontal line across the page such the the perpendicular y distance to the line from all points in aggregate is minimized. Describe an algorithm…

Chander Shivdasani
- 382
- 1
- 4
- 10
2
votes
2 answers
Algorithm to solve this "treefarm" puzzle
How would I go about writing a program to solve this kind of puzzle:
The green squares represent trees, and you have to plant them in such a way, so that:
Trees do not touch each other at all (not even diagonally)
Each row and column contain a…

sammko
- 123
- 2
2
votes
1 answer
Solving a Sudoku variant with an unknown element
I recently stumbled upon a special Sudoku variant and am now struggling to effectively solve it programatically.
Consider the following initial 6x6 grid:
The rules
The red question mark is supposed to represent our secret digit. The secret digit…

MCL
- 129
- 3
1
vote
1 answer
What is the right algorithm to solve this problem?
The problem is -
We have a series of boxes (A, B, C, D, ...).
Each box contains bricks of different colours. For eg.
Box A - red, blue
Box B - blue, red, green
... and so on...
and there are multiple versions of each of the boxes -
Box A1 -…

Shubham Kanodia
- 119
- 1
1
vote
2 answers
What is a O(n) algorithm to solve this puzzle?
We are going to hold a meeting where everybody will speak in clockwise direction around a table. There are n people with n spots. Each person has a position preference (e.g. some want to go first, some last, etc). Everyone is seated randomly and…

d'alar'cop
- 121
- 5
1
vote
1 answer
Reading graph inputs for a programming puzzle and then solving it
I just took a programming competition question and I absolutely bombed it. I had trouble right at the beginning itself from reading the input set. The question was basically a variant of this puzzle http://codercharts.com/puzzle/evacuation-plan but…

Vrashabh Irde
- 442
- 6
- 13
1
vote
3 answers
Backtracking with Killer Sudoku
I'm developing a Killer Sudoku solver for a school project. I've programmed 10 human strategies showing what they are doing in order to be the most educational possible.
It can solve hard Killer Sudokus right now but my teacher proposed that I use…

Cydonia7
- 389
- 1
- 3
- 11
0
votes
1 answer
Find two horizontal lines to minimize distance to scattered points
I am having trouble with a coding question that I found practicing for a interview:
A scatter graph of points on a page, draw two horizontal lines (these lines are parallel) across the page such that the perpendicular y distance to a line from all…

Hyperion
- 21
- 1