Check if a number is majority element in the sorted array

input:nums=[2,4,5,5,5,5,5,6,6], target=5return True
low=0
high=len(nums-1)
n=len(nums)//2
while(low<high):
mid=(low+high)/2
if(nums[left]<target):
low=mid+1
else:
high=mid
return (low + n/2<len(nums) and nums[low + n/2]==target)

--

--

--

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Remix — Not just another javascript framework

Solution of numerical calculation accuracy problem in JavaScript strategy design

Lodash in 2021: Necessary or Obsolete?

Optimising Javascript Code

How to build a real world application using Angular 9.

Reusable Navigation Bar With Drawer In Angular

JavaScript — How to Remove the first characters of a string

How scroll to ID and center it to the screen

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

More from Medium

Two Sorting Algorithms You Must Know About — Quick Sort and Merge Sort

I’ve been building software for coming up 2 decades, and most of it (about 70% of it) remotely.

All You Need to Know About “Algorithms Complexity Analysis” and Big O

Quick Sort (With 3 partitions)