InterviewSolution
Saved Bookmarks
| 1. |
The Golomb sequence is a non-decreasing integer sequence in which the n-th term equals the number of times the letter n appears in the sequence. The first few numbers are 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5,...... |
|
Answer» Definitions of a few terms: If n is a POSITIVE integer, SOLVE for it. The goal is to discover the first n Golomb sequence terms. To determine the nth term of a Golomb sequence, use the following recurrence relation:
The following is the Dynamic Programming implementation: void findGolomb(int N){ int dp[N + 1]; // BASE case dp[1] = 1; // Calculating and displaying the first // N terms of Golomb Sequence. for (int i = 1; i <= N; i++) { dp[i] = 1 + dp[i - dp[dp[i - 1]]]; cout << dp[i] << " "; }}Useful Interview Resources
|
|