Given two integers N and K, the task is to generate a bitonic array where the first element is N and every element is at the difference of K.
Input: N = 10, K = 5
Output: 10 5 0 5 10
Input: N = 16, K = 5
Output: 16 11 6 1 -4 1 6 11 16
Approach: The idea is to use recursion to solve this problem. As stated in the problem, the first element of the bitonic array is N. Therefore, append it into the array and solve for the N. Below is the recursive function definition:
- Base Case: When the value of N is less than equal to 0, Then return 1 because now the values will increase.
- Recursive Case: If the value of the N is greater than , Then append N – K and recursively call for the N – K and finally append N.
Below is the implementation of the above approach:
10 5 0 5 10
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find bitonic point in given bitonic sequence
- Generate Bitonic Sequence of length N from integers in a given range
- Count ways to generate N-length array with 0s, 1s, and 2s such that sum of all adjacent pairwise products is K
- Generate all N digit numbers having absolute difference as K between adjacent digits
- Program to check if an array is bitonic or not
- Sort a Bitonic Array
- Find an element in Bitonic array
- Print all sequences starting with n and consecutive difference limited to k
- Maximum Length Bitonic Subarray | Set 1 (O(n) time and O(n) space)
- Maximum Length Bitonic Subarray | Set 2 (O(n) time and O(1) Space)
- Number of bitonic arrays of length n and consisting of elements from 1 to n
- Longest alternating sub-array starting from every index in a Binary Array
- Find starting index for every occurrence of given array B in array A using Z-Algorithm
- Generate Array whose difference of each element with its left yields the given Array
- Printing Longest Bitonic Subsequence
- Longest Bitonic Subsequence in O(n log n)
- Maximum sum bitonic subarray
- Length of longest strict bitonic subsequence
- Queries on insertion of an element in a Bitonic Sequence
- Maximum product of bitonic subsequence of size 3
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.