string puzzles

2 easy string puzzles. From http://www.careercup.com/question?id=5642266903314432: Given a mapping configuration such as: 1:a 2:b ... 26:z And a string like "12632", print the number of different ways you can map such string to alphabet characters. For example, given "111" the answer is…

Read full post

spiral matrix

From http://www.programcreek.com/2013/01/leetcode-spiral-matrix-java/. Print a matrix in spiral order. My solution destroys the original matrix (makes it easy to handle matrixes that are not square), this would be a good idea to ask the interviewer if that's ok! In Python: …

Read full post

word ladder

From http://www.programcreek.com/2012/12/leetcode-word-ladder/. Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that only one letter can be changed at a time, and each intermediate word must exist in the dictionary. This one…

Read full post

breaking up some tuples

This is a rather specific problem and somewhat contrived. Found on careercup.com. There is an array of 3-tuple, in the form of (a, 1, 5). The first element in the tuple is the id, the second and third elements are both integers, and the third is always larger than…

Read full post

heapsort

Heap Sort In part 4 of MIT 6006 goes into heap data structures and heap sort. Heap sort runs in O(nlog n) time provided the array is already a heap and displays the heap invariant: that each parent node is greater than or equal to both its children. The…

Read full post