Tag Archives: interview questions

Cyclic Linked List – finding the start of the loop using Python

I’d blogged previously about writing a python function to find out whether a linked list is cyclic or acyclic – it’s worth a read before tackling this one. The challenge here is to return the node that is at the … Continue reading

Posted in programming | Tagged , , , | Leave a comment

Puzzle – A safe place to drop an egg

This is a problem where it’s fairly easy to find the solution via trial and error, but not so easy to generalize. Question Let’s say you need to find out the highest floor in a 100 story building from which … Continue reading

Posted in puzzles | Tagged | 1 Comment

Alternating coin toss – redux

I want to revisit a probability puzzle from a previous post: see Alternating coin toss game. You play a game where you alternate tossing a coin with a friend, and the first person to toss heads wins. But let’s make … Continue reading

Posted in puzzles | Tagged , | Leave a comment

Puzzle – Break a stick to get a triangle

I read somewhere this is a Google interview question: Let’s say you drop a stick, breaking it randomly in 2 places, leaving you with 3 smaller sticks.   What’s the probability you can make a triangle out of the 3 resulting … Continue reading

Posted in puzzles | Tagged , | Leave a comment

Puzzle – shortest road system

Let’s say you’re contracted to build roads to connect four towns that are at the corners of an imaginary square with sides 1 mile. What’s the shortest length of road system you can build so that every town can get … Continue reading

Posted in puzzles | Tagged , | 4 Comments

Puzzle – Clock

It’s 3 O’Clock. What will be the time when the minute and hour hands are next in the same position (coincident)? One way to solve this problem:  start with the minute hand at the 12 and hour hand at the … Continue reading

Posted in puzzles | Tagged , , | 5 Comments

More puzzles…

Some of these are from Heard on the Street – a book of interview questions for Quants I’m trying to get through. Well worth a read if you’re into this sort of thing… 1. Two ropes of different lengths, and … Continue reading

Posted in puzzles | Tagged , , | 2 Comments

Mth to last – a recursive approach in Python

A collegue of mine was pondering the mthToLast problem for a LinkedList I’d blogged about previously and sent me the following IM message: just a guess – but can you use recursion to solve your link list m problem? a … Continue reading

Posted in programming | Tagged , , , | Leave a comment

Reverse a string using recursion in Python

I’ve always found recursion somewhat unnatural to think about, but somehow satisfying when I can see it unfolding in my mind – this simple exercise in reversing a string using recursion is a case in point… >>> def reverse(str): if … Continue reading

Posted in programming | Tagged , , | Leave a comment

Deep copy and recursive references

Quick one about coding a deep copy and avoiding recursive references… Let’s say we have an instance a which has a reference to an instance b and we have to do a deep copy of a. To do this, we … Continue reading

Posted in programming | Tagged , , | 3 Comments