Iteration is the repetition of a process in a computer program, usually done with the help of loops. There are two types of loop:
Correctness of Iterative code : How would we prove that the iterative code is correct? In computer science, you could prove it formally with a loop invariant which is divided into the following three parts:
Two pointer approach: This is an iterative approach of problem solving which involve two pointers. We can solve several interview problems in array, linked list and string using this approach. Here are two varition of this approach :
| # | Title | Solution | Difficulty | Companies |
|---|---|---|---|---|
1. | Iteration: Initialization, Maintenance and Termination | |||
2. | Example 1 : Largest element in an array | EASY | ||
3. | Example 2 : Max and Min in an array | MEDIUM | Microsoft Facebook | |
4. | Two Pointer Approach | |||
5. | Example 1 : Reverse an array | EASY | ||
6. | Example 2 : Selection sort | MEDIUM | ||
7. | Example 3 : Insertion Sort | MEDIUM | ||
8. | Example 4 : Minimum Absolute Difference in an Array | MEDIUM | Microsoft Amazon |