You are on page 1of 10

CSE Blog - quant, math, computer science puzzles: DifficultPu...

1 of 10

http://www.cseblog.com/search/label/DifficultPuzzles

CSE Blog - quant, math, computer science puzzles


Quant, Math & Computer Science Puzzles for Interview Preparation & Brain Teasing
A collection of ~225 Puzzles with Solutions (classied by diculty and topic)

Showing posts with label DicultPuzzles. Show all posts


Aug 26, 2013

Number of Paths in Rectangular Grid


Source: Solved it during Algorithms Course under Prof Diwan, and discussed with Nikhil Jain (IT
BHU 2008 Alumnus, Product Manager at AskLaila)
Labels by Diculty

DicultPuzzles (64)

Problem:

EasyPuzzles (87)
MediumPuzzles (93)
Labels by Topic

1. (Easy)
Consider a n x m rectangular grid. The problem is to find the number of shortest (or monotonic in this case)
paths along the edges of the cell that start at (0,0) and end at (n,m).

Algorithm-DataStructures (38)
Brain-Teasers (73)
Discrete-Mathematics (98)

A monotonic path is a path always moving towards the goal, i.e. consists of moving up or right but not down or
left. Figure 1 illustrates such a path for a grid of size 5 x 3.

Engineering-Mathematics (19)
Geometry (25)
Number-Theory (31)
Probability (79)
Strategy-Puzzles (50)
Social
Like

Sanchit Jain, Barun Kumar


Kejriwal and 2,544 others like
this.

Buy me Coee / Beer via Paypal

2. (Dicult)
Now we need to print all monotonic paths that do not go above the diagonal y = x. Figure 2 shows such a path.
Note that the path in figure 1 goes above the diagonal, hence not desirable in this case. How many such paths
exist for n x m grid (n >= m)?

Pages

Home
Books/Study Material

Disclaimer:
The rst problem is too simple, and the second is very challenging. Have fun :-)

Social Pages
Post a Question
About Author
Disclaimer

You might also like


Most popular Puzzle Books for Technical / Quant Finance Interviews
Find Fixed Point (x[i]=i) in an Array

Hits (All Time)

Original Puzzle: Pattern Lock - Combinatorics Puzzle - Number of Possible Passwords

483,865

Determinant of Binary Matrix


Recommended by

Blog Archive

Friday 27 September 2013 01:47 AM

CSE Blog - quant, math, computer science puzzles: DifficultPu...

2 of 10

2013 (34)

14 comments:

Sep 2013 (1)

http://www.cseblog.com/search/label/DifficultPuzzles

+1 Recommend this on Google

Labels: Algorithm-DataStructures, DicultPuzzles, Discrete-Mathematics, Puzzles, UnsolvedPuzzles

Aug 2013 (10)


Chess 5 Piece Puzzle
Number of Paths in Rectangular Grid
Divisibility Problem
Most popular Puzzle Books for Technical /
Quant Fi...
Find Fixed Point (x[i]=i) in an Array

Aug 17, 2013

Walking Ant Problem - Part 2


Source: Original problem adapted from the "Ants Problem" at "CMU ACM Programming Contest"
. Extension to the 4 year old problem on CSE Blog - Walking Ants Puzzle

Walking Ant Problem - Part 2


Guide to Wall Street Quant Jobs for IITians

Problem:

Minimum Point in a Rotated Sorted Array


Probability Puzzle: Expected Number of
Expression ...
Combinatorics + Game Theory Puzzle
Jul 2013 (4)
Jun 2013 (2)
May 2013 (3)
Apr 2013 (5)
Mar 2013 (3)
Feb 2013 (3)
Jan 2013 (3)

You have a bunch of ants on a meter stick, each walking 1cm/s in some direction. If an ant hits
the end of the stick, it falls o. If two ants collide, they both reverse direction.

2012 (39)
2011 (43)

Walking Ants Puzzle earlier essentially asked: Given the starting positions and directions of all
the ants, how long until the last ant falls o?

2010 (80)
2009 (63)
2008 (4)

The new problem is :


Given the starting positions and directions of all the ants, which ant(s) are the last to fall o?

Labels

Disclaimer: I do not have the solution to the problem. It just looks like an interesting problem to
solve.

Puzzles (251)
UnsolvedPuzzles (45)
Innovate (9)

( Readers Please ignore: Technorati claim: 6QVZ8YSY6XSD )

PopularArticles (9)
Coding (8)
UnsolvedCoding (4)
OpenEndedPuzzles (3)

3 comments:

Open Source (2)

+1 Recommend this on Google

Labels: Algorithm-DataStructures, Brain-Teasers, DicultPuzzles, Innovate, OpenEndedPuzzles, Puzzles,


UnsolvedPuzzles

Popular Posts

Integer Points
Jul 28, 2013

Lion in a Circular Cage Puzzle


Geometry Puzzle: Center of Square in Circle

Self Referential Problem - from "What would Martin Gardner Tweet"

Coin Puzzle: Predict the Other's Coin

Source: The Math Factor (contains spoilers) - also tweeted on What Would Martin Gardner Tweet

Asking a girl out

Problem:
The number of 1s in this paragraph is ___; the number of 2s is ___; the number of 3s is ____; and
the number of 4s is ___.

Consecutive Heads
Pizza Distribution Puzzle

Bonus Research Follow-up Problem:


The number of 1s in this paragraph is ___; the number of 2s is ___; ..(and so on) and the
number of Ns is ___.
For N=2 or 3, there are no solutions (Asking that all the numbers we ll in are between 1 and N);
for N=4 there are two. For N=5 there is just one, for N=6 there are none and beyond that there
is just one.
Prove it.

Coins Puzzle
Sphagetti Breakfast
Math Game of Zero String

Follow by Email!

Submit
3 comments:

+1 Recommend this on Google

Labels: Brain-Teasers, DicultPuzzles, Puzzles, UnsolvedPuzzles

Jan 26, 2013

Determinant of Binary Matrix


Source: Introduced to me by Sudeep Kamath (PhD Student, UC at Berkeley, EE IITB Alumnus

Friday 27 September 2013 01:47 AM

CSE Blog - quant, math, computer science puzzles: DifficultPu...

3 of 10

http://www.cseblog.com/search/label/DifficultPuzzles

2008)
Problem:
An N by N matrix M has entries in {0,1} such that all the 1's in a row appear consecutively. Show
that determinant of M is -1 or 0 or 1.
Disclaimer:
I could not solve it but I have an awesome solution sent by Pritish Kamath (MSR Research
Assistant, CSE IITB Alumnus 2012)
Update (2/4/2013):
Solution posted by Amol Sahasrabudhe (IITB 2004 Alumnus, Ex-Morgan Stanley Quant Associate,
Deutsche Bank Quant Associate) and Piyush Sao (EE IITM Alumnus, Georgia Tech Grad Student)
in comments! Thanks a ton. I have posted the solution provided by Pritish Kamath (MSR
Research Assistant, CSE IITB Alumnus 2012). All three solutions are essentially the same.

8 comments:

+1 Recommend this on Google

Labels: DicultPuzzles, Discrete-Mathematics, Engineering-Mathematics, Number-Theory, Puzzles

Dec 31, 2012

Romanian Informatics Olympiad - Modied Human Encoding


Source: (Romanian Informatics Olympiad ONI'03, extended team selection)

( ^ Representative diagram of Human Encoding. No relevance in the problem)


Problem:
A telegraph machine can transmit only lines and dots; it takes 2 seconds to transmit a line, but
only 1 second to transmit a dot. We generally want to transmit texts containing letters of the
English alphabet, and digits (so we have N<=36 symbols in total). Therefore, a prex-free
encoding using lines and dots is needed. Given the frequencies of the N symbols in a large text,
nd the minimum time it takes to transmit the text using a suitable encoding. The solution
should run in O(N^4) time, and use O(N^3) space.

1 comment:

+2 Recommend this on Google

Labels: Algorithm-DataStructures, DicultPuzzles, Discrete-Mathematics, Puzzles, UnsolvedPuzzles

Dec 30, 2012

Coin Puzzle: Predict the Other's Coin


Source: Puzzle collection by Raphael Reischuk

Problem:
Assume the following 3-player game consisting of several rounds. Players A and B build a team,
they have one fair coin each, and may initially talk to each other. Before starting the rst round,
however, no more communication between them is allowed until the end of the game. (Imagine

Friday 27 September 2013 01:47 AM

CSE Blog - quant, math, computer science puzzles: DifficultPu...

4 of 10

http://www.cseblog.com/search/label/DifficultPuzzles

they are separated in dierent places without any communication infrastructure.)


A round of the game consists of the following steps:
(1) the team gives one dollar to player C.
(2) Both A and B toss their coins independently.
(3) Both A and B try to predict the other's coin by telling the guess to C. (No communication: A
does not know the outcome of B's coin toss, and vice versa, nor the guess).
(4) If C veries that both A and B guess the other's coin correctly, then C has to give 3 dollars
back to the team.
Should C play this game?
Previously Asked Coin Puzzles:
Coin Balancing
Coins Puzzle
Consecutive Heads
Five Thieves and Bounty
Update:
Discussion on Hacker News: http://news.ycombinator.com/item?id=4985537
Update: (29 Jan 2013)
Correct solution by: Takaki, Andre, Felix, JDGM in comments!
Correct strategy (but not so correct calculation) by Joshua, Shubham Mittal in comments!
If you are just looking for the solution, Perfect solution by Andre. Thanks

17 comments:

+2 Recommend this on Google

Labels: DicultPuzzles, Probability, Puzzles, Strategy-Puzzles

Dec 13, 2012

Geometry Contruction - Bisect Areas of 2 Triangles


Source: Asked to me by Sankeerth Rao (EE IITB 4th year Student)
Problem:
Given any two triangles in a plane construct a line which bisects both their areas.
Background:
In fact the existence of such a line is true in a very general setting - for any two polygons in a
plane there exists a line which bisects both their areas. In fact its true for any two Jordan
measurable sets in a plane. Further generalized version is called the Ham Sandwich Theorem
and is proved using Borsuk Ulam Theorem.

11 comments:

+2 Recommend this on Google

Labels: DicultPuzzles, Engineering-Mathematics, Geometry, Puzzles, UnsolvedPuzzles

Nov 10, 2012

Sam Loyd Puzzle Solvability


Source: 15 Puzzle
Problem: The 15-puzzle (also called Gem Puzzle, Boss Puzzle, Game of Fifteen, Mystic Square and many
others) is a sliding puzzle that consists of a frame of numbered square tiles in random order with one tile missing.
The object of the puzzle is to place the tiles in order (from gure at left to gure at right) by making sliding moves
that use the empty space. Prove that the 15 puzzle in the conguration as shown on the left is not solvable.

Related Links:

Friday 27 September 2013 01:47 AM

CSE Blog - quant, math, computer science puzzles: DifficultPu...

5 of 10

http://www.cseblog.com/search/label/DifficultPuzzles

I made this fb game yesterday night - 9 Puzzle over Movie Posters - Movie Sliding Puzzle
Sam Loyd published some great puzzles in his time. One book that gets recommended a lot is
"Sam Loyd's Cyclopedia of 5000 Puzzles tricks and Conundrums" (Amazon , Flipkart)
Update: (24/12/2012)
Solution provided by Raghuram Kowdeed (IIT Kanpur) in comments!
Update: (24/12/2012)
Same solution posted by Sai Teja Pratap (IIT Bombay CSE Final Year Student) and Eeshaan
Malhotra (IIT Bombay) on Quora Board.

2 comments:

+3 Recommend this on Google

Labels: DicultPuzzles, Discrete-Mathematics, Puzzles

Oct 18, 2012

Strategy Game - Similar to Nim


Source: Posted at "Post a Question"
Problem:
Two players compete in the following game: There is a pile containing n chips; the rst player
removes any number of chips except that he cannot take the whole pile. From then on, the
players alternate moves, each person removing one or more chips but not more than twice as
many chips as the preceding player has taken. The player who removes the last chip wins. (For
example, suppose that n = 11; player A removes 3 chips; player B may remove up to 6 chips,
and he takes 1. There remain 7 chips; player A may take 1 or 2 chips, and he takes 2; player B
may remove up to 4, and he picks up 1. There remain 4 chips; player A now takes 1; player B
must take at least one chip and player A wins in the his next chance.
What is the best move for the rst player to ensure his win if possible if there are initially n
chips?

8 comments:

+1 Recommend this on Google

Labels: DicultPuzzles, Discrete-Mathematics, Puzzles, Strategy-Puzzles, UnsolvedPuzzles

Sep 25, 2012

USA Maths Olympiad Problem - 200th Puzzle


200th Puzzle of the CSE Blog
Source:
I got hold of the super awesome book I read 6 years back: "A Path to Combinatorics for
Undergraduates: Counting Strategies". A must have for any math/olympiad enthusiast (Flipkart
link to Imported Edition and Indian Edition) - Example 5.8 - USAMO 1990
Problem:
Let n be a positive integer. Find the number of positive integers whose base n representation
consists of distinct digits with the property that except for the leftmost digit, every digit diers
by +1 or -1 from some digit further to the left.
Update (26/12/2012):
No correct solution provided. Solution posted by me in comments!

8 comments:

+3 Recommend this on Google

Labels: DicultPuzzles, Discrete-Mathematics, Number-Theory, Puzzles

Apr 8, 2012

Original Puzzle: Pattern Lock - Combinatorics Puzzle - Number of


Possible Passwords

Friday 27 September 2013 01:47 AM

CSE Blog - quant, math, computer science puzzles: DifficultPu...

6 of 10

http://www.cseblog.com/search/label/DifficultPuzzles

Source: Discussion with Ankush Jain (CSE IITB 2011 Alumnus, Morgan Stanley Analyst) a few
months back. Discussion revived by Sangram Raje (CSE IITB 2008 Alumnus, Tower Research
Analyst) today.
Problem:
Ever seen a pattern lock in Galaxy S2? Password is a series of connected line strokes. How many
possible password combinations can you have?
Some description about the problem:
1) Assuming the dots on the screen are like (1, 2, 3 in the rst row), (4, 5, 6 in the second row)
and (7, 8, 9 in the third row), you cannot go to 8 from 2, without going through 5. So, a password
like * * 8 2 * * is not possible.
2) You cannot move over two lines twice You can move to a used point, but you cannot move to
another used point from a used point
I do not see a simple way to solve this. But even coding this looks very dicult to me. Any
takers?
Update: (19-07-2012)
This is essentially an open ended question

5 comments:

+3 Recommend this on Google

Labels: DicultPuzzles, Discrete-Mathematics, OpenEndedPuzzles, Puzzles

Oct 31, 2011

Sphagetti Breakfast
Source: Very standard problem in Quant interviews (Taken from quantnet, xkcd forums)

Problem:
A bowl of spaghetti contains n strands. Thor picks two ends at random and joins them together.
He does this until no ends remain.
What is the
a) expected number of spaghetti loops in the bowl?
b) expected average length of the loops? (in strands)
c) expected number of k-hoops? ( a k-hoop is a loop made from k strands)

8 comments:

+1 Recommend this on Google

Labels: DicultPuzzles, Probability, Puzzles, UnsolvedPuzzles

Sep 4, 2011

Arrange in a Sequence
Source:
Asked to me by Amol Sahasrabudhe (IITB 2004 Alumnus, Worked at Morgan Stanley Quant
Division, Deutsche Bank)
Problem:
You are given 2n numbers ( 1 to n and 1 to n ). You have to arrange these numbers in a
sequence such that between any two i`s , there exists exactly i-1 numbers. Is it possible for all
n? If no, what are the values of n for which this is possible?

Friday 27 September 2013 01:47 AM

CSE Blog - quant, math, computer science puzzles: DifficultPu...

7 of 10

http://www.cseblog.com/search/label/DifficultPuzzles

Disclaimer:
I have not been able to solve it. Sudhanshu Tungare (IITB 2008 EE Alumnus, Morgan Stanley)
claims to have a solution. Cheers!
Update (November 1, 2011):
Part solution posted by Nishant Totla (CSE IITB Senior Undergraduate), Richie and Sarat in
comments! Complete solution posted by Siddhant Agarwal (EE IITB Alumnus, CMI Grad student)
in comments! Thanks a ton.

7 comments:

Recommend this on Google

Labels: DicultPuzzles, Discrete-Mathematics, Engineering-Mathematics, Puzzles, Strategy-Puzzles

Aug 17, 2011

Sacred Right Pan - IMO 2011 Problem


Source: IMO 2011 Problem (sent to me by Dinesh Dharme, CSE IITB 2011 Alumnus, Credit
Suisse Analyst)

Problem:
Let n > 0 be an integer. We are given a balance and n weights of weight 2^0, 2^1, . . . ,
2^(n1). We are to place each of the n weights on the balance, one after another, in such a way
that the right pan is never heavier than the left pan. At each step we choose one of the weights
that has not yet been placed on the balance, and place it on either the left pan or the right pan,
until all of the weights have been placed.
Determine the number of ways in which this can be done.
Disclaimer:
As expected from an IMO problem, very dicult! But interesting solutions at
www.math.leidenuniv.nl/~desmit/pop/2011_imo_nal6.pdf
Update (25 Aug 2011):
I did not write in clearly in the post. One of the solutions provided in the pdf is an oral 3 line
solution to the problem. It cannot get smaller than this :P. Even if you have solved the problem,
do have a look at the pdf

3 comments:

Recommend this on Google

Labels: DicultPuzzles, Discrete-Mathematics, Number-Theory, Puzzles

Jul 6, 2011

Expectation of Max Frequency


Source: Sent to me by Nikhil Garg (CSE Senior Undergrad, IITD) - who got this from Rudradev
Basak
Problem:
There are K balls in a sack numbered 1 to K. Bob chooses a ball at random notes down its
number and puts it back in sack. He does this process for N times. What is the expected value of
the frequency of the most frequent element ?
Best of Luck! I do not have the solution. So, tell me if you get one. Thanks.

1 comment:

Recommend this on Google

Labels: DicultPuzzles, Discrete-Mathematics, Probability, Puzzles, UnsolvedPuzzles

Feb 25, 2011

Coin Toss Bankruptcy

Friday 27 September 2013 01:47 AM

CSE Blog - quant, math, computer science puzzles: DifficultPu...

8 of 10

http://www.cseblog.com/search/label/DifficultPuzzles

Source: Mailed to me by Sudeep Kamath (EECS PhD Student, UC Berkeley, EE IITB 2008
Alumnus)

Problem: Three people start with integer amounts a,b and c. In each round, each one tosses a
fair coin. If not all faces are the same, the person with the dierent face gets a rupee from each
of the other two. If all faces are the same, no money is exchanged. This process is repeated till
one of them gets bankrupt. What is the expected number of rounds till the game ends?
Related Problems:
http://pratikpoddarcse.blogspot.com/2009/10/lets-say-keep-tossing-fair-coin-until.html
http://pratikpoddarcse.blogspot.com/2010/11/source-credit-suisse-placement-test-at.html
http://pratikpoddarcse.blogspot.com/2011/02/equal-heads-and-tail.html
Update (15/03/2011):
Hint: Given away by Sudeep. (* Dene a martingale of the form
Y_n=A_n*B_n*C_n + some other term (where A_n,B_n,C_n are the fortunes
of the three players at time n). *)
Solution: Posted by chera (Gaurav Sinha, IITK 1996 Graduate, Indian Revenue Service) in
comments!

8 comments:

Recommend this on Google

Labels: DicultPuzzles, Engineering-Mathematics, Probability, Puzzles

Feb 6, 2011

Equal Heads and Tail


Source: Posted by chera (Gaurav Sinha, IITK 1996 Graduate, Indian Revenue Service) in
comments on Consecutive Heads Problem
Problem:
Suppose you have a fair coin and you toss it until you have got equal number of heads and tails.
What is the expected number of tosses? Note that probability that the game stops in odd
number of tosses is 0. The probability that the game stops in 2 tosses = 0.5
Solution:
Dierent solutions posted by Kalyan Parhi (EE IITB Alumnus), Abhash, Siva, Gaurav Sinha (CSE
IITK 1996 Alumnus, Indian Revenue Service), Dinesh Krithivasan (IITM Alumnus, Phd University of
Michigan, Senior Qualcomm Engineer) in comments!

15 comments:

Recommend this on Google

Labels: DicultPuzzles, Discrete-Mathematics, Probability, Puzzles

Jan 27, 2011

Expectation of 2^(Cycle Length)


Source: Mailed to me by Sudeep Kamath (EECS PhD Student, UC Berkeley, EE IITB 2008
Alumnus), Taken from Anand Sarwate (Postdoc at UC San Diego, PhD from UC Berkeley)
Problem:
Given a permutation p of length n, let c(p) be the number of cycles in p. Suppose p is drawn
uniformly from the set of all permutations. Show that
Expectation of 2 raised to the power of number of cycles is n+1, i.e E[2^c(p)]=(n+1)
Hint:
1) There is no high funda group theory/number theory involved. I could solve this in 15 minutes
\m/ \m/
2) After you are done, you might want to read this (*Spoiler Alert*)
Solution:
Hint posted by Nikhil Garg (CSE, IIT Delhi third year undergraduate student) in comments!
Solution posted by Kalyan in comments! Kalyan's comment explained in detail by me in
comments! A simpler solution posted by Gaurav Sinha (chera) (CSE IITK 1996 Alumnus, Indian
Revenue Service) in comments!

10 comments:

Recommend this on Google

Labels: DicultPuzzles, Discrete-Mathematics, Number-Theory, Probability, Puzzles

Jan 20, 2011

Friday 27 September 2013 01:47 AM

CSE Blog - quant, math, computer science puzzles: DifficultPu...

9 of 10

http://www.cseblog.com/search/label/DifficultPuzzles

CMU Puzzle Toad: Abduction


Source: CMU Puzzle Toad
Problem: Farmer Brown is standing in the middle of his perfectly circular eld feeling very
content. It is midnight and there is no moon and unknown to the farmer, Martian zoologists are
landing randomly at points on the circumference of his eld. They land at one minute intervals,
starting at midnight. As soon as there are martians at points A,B,C such that triangle ABC
contains the center of the eld, Farmer Brown will be teleported to the waiting space-ship and
transported to spend the rest of his life as an exhibit in a Martian zoo. What is the expected time
until he is abducted?
Related Problem: http://pratikpoddarcse.blogspot.com/2009/10/semi-circle-covering-n-pointspuzzle.html
Solution: Posted on CMU Puzzle Toad (http://www.cs.cmu.edu/puzzle/solution33.pdf). Check my
name in the acknowledgments \m/ \m/
You might also like
Coins Puzzle
Break the sticks
Homo paradox
Ants on a Cube
Recommended by

2 comments:

Recommend this on Google

Labels: DicultPuzzles, Geometry, Probability, Puzzles

Dec 8, 2010

Locks and Switches


There is a lock which is an N by N grid of switches. Each switch can be in one of two states
(on/o). The lock is unlocked if all the switches are on. The lock is built in such a way that, if you
toggle some switch, all the switches in its row and its column toggle too
Give an algorithm which, given N and a conguration of the N^2 switches, will tell you whether
the lock can be unlocked by a sequence of switch toggles
Note 1: Can be done in O(N^2) time and O(1) space.
Note 2: You just need to tell if a sequence which unlocks the lock exists (and not the actual
sequence)
Update (Dec 20, 2010):
Complete solution posted jointly by Siddhant Agarwal (EE, Final year student, IITB) and Gaurav
Sinha (IITK 1996 CSE Alumnus, IRS Ocer). Thanks a lot
You might also like
Guide to Wall Street Quant Jobs for IITians
Walking Ant Problem - Part 2
Math Olympiad Problem : Overlapping Coins
Odd Even Algorithm Puzzle
Recommended by

10 comments:

+1 Recommend this on Google

Labels: Algorithm-DataStructures, DicultPuzzles, Discrete-Mathematics, Puzzles

Home

Older Posts

Subscribe to: Posts (Atom)

Friday 27 September 2013 01:47 AM

CSE Blog - quant, math, computer science puzzles: DifficultPu...

10 of 10

http://www.cseblog.com/search/label/DifficultPuzzles

Banner

Contributors

amit upadhyay
Pratik Poddar

About CSE Blog

"CSE Blog - Quant, Math & Computer Science Puzzles for Interview
Preparation & Brain Teasing" is a collection of ~225 Puzzles with Solutions.
The problems are divided into three sections: (Easy, Medium and Dicult)
CSE Blog - quant, math, computer science puzzles. Simple template. Powered by Blogger.

Friday 27 September 2013 01:47 AM

You might also like