Sep 14, 2024
n
and n-1
numbers in an array containing numbers between 1
to n
.n = 5
, if array = [1, 2, 4, 5], missing number is 3
.1
to n
and check if it exists in the array.1
to n
.O(n^2)
in the worst case.O(1)
.n+1
initialized to 0
.0
.O(n)
.O(n)
.Method 1: Sum Formula
n
natural numbers: n(n + 1) / 2
.O(n)
.O(1)
.Method 2: ZOR
x ⊕ x = 0
for any integer x
.1
to n
and all elements in the array. The result will be the missing number.O(n)
.O(1)
.0s
and 1s
, find the length of the longest subarray of 1s
.1s
and the maximum count.1
, increment the counter.0
, reset the counter.O(n)
.O(1)
.O(n^2)
.O(1)
.O(n)
.O(n)
.ZOR
to 0
.O(n)
.O(1)
.