I don’t quite remember where I saw this problem, but I’m sure it’s appeared in a number of places. Given two strings \(s\) and \(t\), determine whether a string \(u\) is formed by interweaving \(s\) and \(t\). That is, determine whether \(u\) can be formed by taking the first few characters of (say) \(s\), followed by the first few characters of \(t\), then the next few characters of \(s\), and so on. For example, the string “abccdcxey” can be formed by interweaving “abcde” with “ccxy”… » [Expand post] [Permalink]
Tag Archive for 'programming exercises'
Programming exercise: interweaved strings
[Permalink]If you like this post, you might also like:
Programming exercise: red-white-blue sorting
[Permalink]I’ve been practising coding on the whiteboard for job interviews. This is very different than coding in front of a computer which has a keyboard, a monitor, and a nice editing program that allows you to correct your mistakes and type repetitive text very quickly. I’m trying to keep my programs simple and short, and writing in a C-like pseudocode.
This exercise comes from Skiena’s The Algorithm Design Manual[1]\(\)… » [Expand post] [Permalink]
Lists of programming exercises
[Permalink]I’ve collected a number of web sites with lists of programming exercises, which I’m going through for practice.
In no particular order, these are… » [Expand post] [Permalink]
Programming exercise: permutations of a string
[Permalink]The problem is to implement a function that outputs all possible permutations of the characters in a string. Unlike combinations, two permutations are considered distinct if they contain the same characters, but in a different order. Also, for the purposes of this exercise, each occurrence of a repeated character is considered to be a distinct character. That is, if the input is “aaa”, the output should be six repetitions of “aaa”. The permutations may be output in any order.
This exercise, like the previous one on combinations of a string, is from the book Programming Interviews Exposed by John Mongan and Noah Suojanen[1]\(\)… » [Expand post] [Permalink]
Programming exercise: combinations of a string
[Permalink]The problem is to implement a function that outputs all possible combinations of the characters in a string (with length ranging from one to the length of the string). Unlike permutations, two combinations are considered to be the same if they contain the same characters, but in a different order. Another way to define the problem is to find the power set of the characters of the string (excluding the empty set).
Like the previous exercise, this one is also from the book Programming Interviews Exposed by John Mongan and Noah Suojanen[1]\(\)… » [Expand post] [Permalink]
Programming exercise: maximum value in integer array, part 1
[Permalink]This exercise is just a little bit more substantial than the last one — but not by very much. Given an array of \(n\) non-negative integers, find the maximum value in the array, or return \(-1\) if the array is empty. Obviously, the use of any built-in maximum-finding function is forbidden. While the problem is almost trivial, it does illustrate how each language works with array or vector data types, as well as how it handles iteration.
This exercise, like some of the other ones that I will also be going through, is from the book Programming Interviews Exposed by John Mongan and Noah Suojanen[1]… » [Expand post] [Permalink]
Programming exercise: Hello, world!
[Permalink]As a preliminary exercise to jog my memory, here is the obligatory “Hello, world!” program in a variety of languages. On the one hand, the programs do nothing except output a string, and so don’t illustrate very much about the respective languages. On the other hand, the simplicity of the task does illustrate the difference between languages that allow you to begin coding right away versus those that require a considerable amount of setting up (importing libraries, declaring classes, etc.) before you even have a functioning program… » [Expand post] [Permalink]
If you like this post, you might also like:
Programming exercises and comparison of programming languages
[Permalink]I started programming when I was eight years old. The first programming language I learned was Basic, followed very shortly by C and 8086 assembly language. During elementary school, I was also exposed to Pascal and Logo. I ignored Pascal because it seemed to me that anything I could do in it I could already do with C, and although I had some fun with Logo’s turtle graphics, I didn’t take it very seriously. At the time, I didn’t appreciate its connection with Lisp and other “serious” programming languages… » [Expand post] [Permalink]