Questions tagged [puzzle]

DO NOT USE - prefer constructive questions, or use more descriptive tags. Otherwise, your question might be appropriate for codegolf.stackexchange.com.

DO NOT USE - prefer constructive questions, or use more descriptive tags. Otherwise, your question might be appropriate for CodeGolf.


The questions tagged "puzzle" are essentially programming questions, that are as good as solving puzzles. These can be contrasted to the real-life problems, which are comparatively easy to solve.

859 questions
715
votes
78 answers

Expand a random range from 1–5 to 1–7

Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7.
praveen
  • 945
  • 3
  • 7
  • 3
386
votes
35 answers

How to find list of possible words from a letter matrix [Boggle Solver]

Lately I have been playing a game on my iPhone called Scramble. Some of you may know this game as Boggle. Essentially, when the game starts you get a matrix of letters like so: F X I E A M L O E W B X A S T U The goal of the game is to find as many…
Paolo Bergantino
  • 480,997
  • 81
  • 517
  • 436
202
votes
46 answers

What is the simplest SQL Query to find the second largest value?

What is the simplest SQL query to find the second largest integer value in a specific column? There are maybe duplicate values in the column.
Niyaz
  • 53,943
  • 55
  • 151
  • 182
153
votes
31 answers

Set every cell in matrix to 0 if that row or column contains a 0

Given a NxN matrix with 0s and 1s. Set every row that contains a 0 to all 0s and set every column that contains a 0 to all 0s. For example 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 results in 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1…
jaircazarin-old-account
  • 2,875
  • 3
  • 20
  • 17
117
votes
37 answers

How to find all combinations of coins when given some dollar value

I found a piece of code that I was writing for interview prep few months ago. According to the comment I had, it was trying to solve this problem: Given some dollar value in cents (e.g. 200 = 2 dollars, 1000 = 10 dollars), find all the combinations…
codingbear
  • 14,773
  • 20
  • 48
  • 64
100
votes
31 answers

Programmer Puzzle: Encoding a chess board state throughout a game

Not strictly a question, more of a puzzle... Over the years, I've been involved in a few technical interviews of new employees. Other than asking the standard "do you know X technology" questions, I've also tried to get a feel for how they approach…
Andrew Rollings
  • 14,340
  • 7
  • 51
  • 50
88
votes
17 answers

How to generate Sudoku boards with unique solutions

How do you generate a Sudoku board with a unique solution? What I thought was to initialize a random board and then remove some numbers. But my question is how do I maintain the uniqueness of a solution?
guilin 桂林
  • 17,050
  • 29
  • 92
  • 146
78
votes
8 answers

The "guess the number" game for arbitrary rational numbers?

I once got the following as an interview question: I'm thinking of a positive integer n. Come up with an algorithm that can guess it in O(lg n) queries. Each query is a number of your choosing, and I will answer either "lower," "higher," or…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
61
votes
7 answers

hello world in C without semicolons and without IF/WHILE/FOR statements

My friend says it's possible to write a C program that will print "hello world" without IF/WHILE/FOR and without semicolons. After minimal research I told her it was not possible. Is it possible?
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
56
votes
14 answers

Algorithm to generate anagrams

What would be the best strategy to generate anagrams. An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; ex. Eleven plus two…
prakash
  • 58,901
  • 25
  • 93
  • 115
48
votes
7 answers

java based programming challenges

Is there any website which provides core java based programming challenges that tests programming logic?
abson
  • 9,148
  • 17
  • 50
  • 69
47
votes
11 answers

How to test randomness (case in point - Shuffling)

First off, this question is ripped out from this question. I did it because I think this part is bigger than a sub-part of a longer question. If it offends, please pardon me. Assume that you have a algorithm that generates randomness. Now how do you…
Tnilsson
  • 2,180
  • 1
  • 15
  • 22
47
votes
39 answers

Algorithm to determine if array contains n...n+m?

I saw this question on Reddit, and there were no positive solutions presented, and I thought it would be a perfect question to ask here. This was in a thread about interview questions: Write a method that takes an int array of size m, and returns…
Kyle Cronin
  • 77,653
  • 43
  • 148
  • 164
45
votes
28 answers

Programming Riddle: How might you translate an Excel column name to a number?

I was recently asked in a job interview to resolve a programming puzzle that I thought it would be interesting to share. It's about translating Excel column letters to actual numbers, if you recall, Excel names its columns with letters from A to Z,…
Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
42
votes
5 answers

Linear Time Voting Algorithm. I don't get it

As I was reading this (Find the most common entry in an array), the Boyer and Moore's Linear Time Voting Algorithm was suggested. If you follow the link to the site, there is a step by step explanation of how the algorithm works. For the given…
Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
1
2 3
57 58