IBM | OA | Bitonic Sequence

Posted
29 Mar 2025
331 reads

Summary

This post details an Online Assessment (OA) at IBM, featuring a problem to find the length of the longest bitonic subarray.

How it went

A bitonic sequence is a sequence of numbers that first increase (non-decreasing) and then decreases (non-increasing). Given an array of integers, find the length of the longest subarray that is bitonic in nature.

Input: arr =[10,8,9,15,12,6,7] Output: 5 [8,9,15,12,6]is the longest bitonic subarray. Return its length, 5.

Input: arr =[5,1,2,1,4,5] Output: 3 [1,2,1]is the longest bitonic subarray. Note that the subarray[1,4,5]is also bitonic in nature and has the same length. It is non-decreasing through[1,4,5]and the non-increasing portion is[5].

Input: arr =[9,7,6,2,1] Output: 5 The non-decreasing subarray is[9]. The non-increasing subarray is the entire array. The entire array has 5 elements.

Constraints: 1 $$≤$$ n $$≤$$ $10^5$ 1 $$≤$$ arr[i] $$≤$$ $10^9$

Questions asked (1)

  1. 01

    Longest Bitonic Subarray

    Data Structures & Algorithms

    A bitonic sequence is a sequence of numbers that first increase (non-decreasing) and then decreases (non-increasing). Given an array of integers, find the length of the longest subarray that is bitonic in nature.

    Input: arr =[10,8,9,15,12,6,7] Output: 5 [8,9,15,12,6]is the longest bitonic subarray. Return its length, 5.

    Input: arr =[5,1,2,1,4,5] Output: 3 [1,2,1]is the longest bitonic subarray. Note that the subarray[1,4,5]is also bitonic in nature and has the same length. It is non-decreasing through[1,4,5]and the non-increasing portion is[5].

    Input: arr =[9,7,6,2,1] Output: 5 The non-decreasing subarray is[9]. The non-increasing subarray is the entire array. The entire array has 5 elements.

    Constraints: 1 $$≤$$ n $$≤$$ $10^5$ 1 $$≤$$ arr[i] $$≤$$ $10^9$

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at IBM recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

Be the first to share your thoughts and start the discussion!