Binary Search - 1
Binary Search - 1
Binary Search - 1
Q1. Given a sorted array of n elements and a target ‘x’. Find the last occurrence of ‘x’ in the array. If ‘x’
Output 1: 6
Q2. Given a sorted binary array, efficiently count the total number of 1’s in it.
Input 1 : a = [0,0,0,0,1,1]
Output 1: 2
Q3. Given a matrix having 0-1 only where each row is sorted in increasing order, find the row with the maximum
number of 1’s.
Input matrix : 0 1 1 1
0 0 1 1
0 0 0 0
Output: 2
Q4. Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n]
There is only one repeated number in nums, return this repeated number.
Output 1: 3
Output 2: 2
Q5. Given a number ‘n’. Predict whether ‘n’ is a valid perfect square or not.
Input 1: n = 36
Output 1: yes
Input 2: n = 45
Output 2: no
Q6. You have n coins and you want to build a staircase with these coins. The staircase consists of k
rows where the ith row has exactly i coins. The last row of the staircase may be incomplete.
Given the integer n, return the number of complete rows of the staircase you will build.
Java
C++ &+ DSA
Example 1:
Input: n = 5
Output: 2
Example 2:
Input: n = 8
Output: 3
Note:- Please try to invest time doing the assignments which are necessary to build a strong foundation. Do not
directly Copy Paste using Google or ChatGPT. Please use your brain.
Java
C++ &+ DSA
DSA