Asked inAmazon,Intern

Given a sorted array of integers, find the frequency of 2 in the array in log(n) time.

AnswerBot
1y

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

Anonymous
1y

Time complexity isO(log)n

Anonymous
1y

Time complexity isO(log)n

Shiva Kumar
1y

Time complexity isO(log)n

Usha Sharma
1y

Time complexity is o(logn)

Anonymous
1y

Time complexity is O(log(n).

Anonymous
1y

Ues binary search to find and last occurrence of 2in array

Shashi Rajak
1y

Time complexity is 0

Jakkula Sai kundana
1y

Time complexity is 0(log(n))

Anonymous
1y

Time complexity is o(login)

Anonymous
1y

Calculate frequency by subtracting last index from first index and adding 1

R Vijay Rams
1y

Calculate frequency by subtracting last index from first index and adding 1

SURAJ SHARMA
1y

Do this without traversing the complete array expected time complexity is less then 0(n)

Rupali Raghorte
1y

Calculate frequency by substacting last index from 1 index and adding1

Anonymous
1y

Time complexity is O(login)

Anonymous
1y

Frequency of 2in the array is<

Anonymous
1y

Use binary search to find first and last occurrence of in array

Antyala Ramya
1y
Calculate frequency by substacting last index from 1 index and adding1
jayasree Matla
1y

Given sorted array arr positive

Anonymous
1y
  • Calculate frequency by subtracting last index from first index and adding 1.

SURE PAVAN KUMAR
1y
  • Time complexity is O(log(n))

Anonymous
1y

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

Harshal Dhamankar
1y
  1. Use binary search to find the first occurrence of 2 in the array.

  2. Use binary search to find the last occurrence of 2 in the array.

  3. Return the difference of the two indices plus 1.

For example, if the arr...read more

Kasthuri
1y
  • 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)).

Kasthuri
1y

// 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

Vani Kranthi
1y

First occurence,last occurence

Shiek Mohammed. S
1y

Time complexity is O(log(n)).

Mohd Aijaz
2y

Last occurrance - first occurrance+1

dilsha jamshad
2y

Add 2 array then divided by total number of araay

Azmi Arshi
2y

Last occurrence - first occurrence + 1

neeraj suryavanshi
2y

(last_occurence - first_occurence + 1)

Sumit
2y

LastLast occurrence -first occurrence+1

Ahbab Ahmad
2y

Last occurrence -first occurrence+1

ARFAT SAGRI
2y

Th e idea take from last occurence

Harshitha Bangaru
2y

Last  occurrence and first occurrence+1  or any alphabet like (X or Y) which means that can be mention anything in first and last . 

Gopi Krishna palaparthi
2y

Last_occurence-frist_occurence+1

Rabi Rajak
2y

(last_occurence - first_occurence + 1)

Amar Bhorawat
2y
(last_occurence - first_occurence + 1)
Anonymous
2y
(last_occurence - first_occurence + 1)
Anonymous
3y
The idea is to use the Binary Search to find the first and the last occurrence of 2 and find the frequency using (last_occurence - first_occurence + 1)
Add answer anonymously...
Amazon Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter