Find frequency of 2 in sorted array of integers in log(n) time.
Use binary search to find first and last occurrence of 2 in array.
Calculate frequency by subtracting last index from first index and addi...read more
Time complexity isO(log)n
Time complexity isO(log)n
Time complexity isO(log)n
Time complexity is o(logn)
Time complexity is O(log(n).
Ues binary search to find and last occurrence of 2in array
Time complexity is 0
Time complexity is 0(log(n))
Time complexity is o(login)
Calculate frequency by subtracting last index from first index and adding 1
Calculate frequency by subtracting last index from first index and adding 1
Do this without traversing the complete array expected time complexity is less then 0(n)
Calculate frequency by substacting last index from 1 index and adding1
Time complexity is O(login)
Frequency of 2in the array is<
Use binary search to find first and last occurrence of in array
Calculate frequency by substacting last index from 1 index and adding1
Given sorted array arr positive
Calculate frequency by subtracting last index from first index and adding 1.
Time complexity is O(log(n))
Use binary search to find first and last occurrence of 2 in arrayUse binary search to find first and last occurrence of 2 in array
Use binary search to find the first occurrence of 2 in the array.
Use binary search to find the last occurrence of 2 in the array.
Return the difference of the two indices plus 1.
For example, if the arr...read more
Use binary search to find first and last occurrence of 2 in array.
Calculate frequency by subtracting last index from first index and adding 1.
Time complexity is O(log(n)).
// C++ program to count occurrences of an element
#include
using
namespace
std;
// Returns number of times x occurs in arr[0.]
int(int
arr[], int
n, int
x)
{
int
res = 0;
for
(int
i=0; i
...read more
First occurence,last occurence
Time complexity is O(log(n)).
Last occurrance - first occurrance+1
Add 2 array then divided by total number of araay
Last occurrence - first occurrence + 1
(last_occurence - first_occurence + 1)
LastLast occurrence -first occurrence+1
Last occurrence -first occurrence+1
Th e idea take from last occurence
Last occurrence and first occurrence+1 or any alphabet like (X or Y) which means that can be mention anything in first and last .
Last_occurence-frist_occurence+1
(last_occurence - first_occurence + 1)
Top Amazon Intern interview questions & answers
Popular interview questions of Intern
Reviews
Interviews
Salaries
Users/Month