Skip to content

Instantly share code, notes, and snippets.

@amatus
Created August 31, 2012 18:11
Show Gist options
  • Save amatus/3556748 to your computer and use it in GitHub Desktop.
Save amatus/3556748 to your computer and use it in GitHub Desktop.
ATX2600 code-down, 2012-02-03
[ problem 1 ]
Given an arbitrary linked list, can you figure out if a loop occurs. Find
a solution that can be done with O(1) space restriction (constant extra
spaced used). You have no knowledge about the length of the list.
Write an algorithm that solves the problem.
[ problem 2 ]
Given a string, find the first occurrence of a letter that does not repeat.
For example, in the string "abcdab", the answer is 'c' (not 'd'). Try to
find a solution with O(n) time.
Input will consist of the alphabet [a-zA-Z] (case sensitive, "Abca" -> 'A').
[ problem 3 ]
Given an array of numbers, find 2 numbers such that their sum is equal to n.
Assume that there will be a pair of numbers that sum to n. If there are
multiple answers, pick any pair.
[ problem 4 ]
Find the kth smallest element in an unsorted array of integers. Find a
solution without fully sorting the array (a partial sort is ok).
[ problem 5 ]
Given a string that represents a C comment, pull out the message in the
comment and strip away extraneous characters:
'*', ' ', '_', '/', '\', '+', '-'
ex: asdf///*_**\\\*****Get Me!*--///*/****//asdf
In that string, "Get Me!" (minus the quotes) would be the result, as it is
inside the comment, but all the extra "*/\-" are removed.
[ bonus ]
Add 1 (one) to a number without using + or - (or arithmetic equivalent).
There is an elegant C solution to this problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment