A feature flag rolls out only if one variant number in nums was chosen by more than half of the users. Nothing is guaranteed this time.
Write trueMajority(nums) that returns the variant chosen more than nums.length / 2 times, or -1 if there is none. Use O(1) extra memory.
Input: nums = [2,2,1,2,3] Output: 2
2 appears 3 times out of 5.
Input: nums = [1,2,3,1] Output: -1
1 appears 2 times out of 4, which is exactly half, not more.
0 <= nums.length <= 10^50 <= nums[i] <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #68 Verify a True Majority. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.