Sunday, August 14, 2016

Coding problems to refresh your brain

Coding problems that I have come across recently:

1. Add two simple mathematical expressions which are of the form Axa + Bxb + ...

2. Print nth number of Fibonacci series using iterative loop.

3. Iterate and print every element of a n-child binary tree

4. Dollar Words:

acalephe
acclimatizable
acclimatizer
acclimatizers
accorage

Using a C# console application, give each letter in each word a numerical value equal to its position in the alphabet.  So "a" is 1 and "z" is 26.  Punctuation and whitespace is 0.  Find words where the sum of the value of the letters is 100 and print each of the “100” words on the console.

5. In the programming language of your choice, write a method that modifies a string using the
following rules:

- Each word in the input string is replaced with the following: the first letter of the word, the count of
distinct letters between the first and last letter, and the last letter of the word. For
example, “Automotive parts" would be replaced by "A6e p3s".
- A "word" is defined as a sequence of alphabetic characters, delimited by any non-alphabetic
characters.
- Any non-alphabetic character in the input string should appear in the output string in its original
relative location

6 a)An array contains 0s and 1s. Write a function to sort all the 0s to the left and the 1s to the right.
b) Check if array is sorted i.e. if all the 0s are to the left and 1s are to the right.

7. Convert date strings in the following formats  'M/d/yyyy' , 'MM/d/yyyy', 'M/dd/yyyy' to 'MM/dd/yyyy'.  This is a real life problem that I had to fix for the dates in my company's database.