# Tag Info

0

Assume elements start at index 0. N is odd. Let mid be an even number close to the middle of the array. Compare a[mid-1] and a[mid]. There is an odd number of elements before mid-1 and an even number after mid. If both numbers are equal then the unique one is in the left half < mid-1. If they are not equal then the unique one is in the right half ...

1

This is a classical problem when the array isn't sorted, which has a surprising, almost magical linear solution. But here, with a sorted array, your idea is great. The unique element will have an index $u$, and every element $a[i]$ will be exactly the same as either $a[i-1]$ or $a[i+1]$ (which are different). Assuming that arrays start at $0$, the shape of ...

0

here, you are multiplying the depth of the "parent" array, instead of the nested array. sum+=(depth)* productSum(array[i],depth+1) try this sum+=(depth+1)* productSum(array[i],depth+1) multiply it by depth+1

0

The data structure itself is unambiguously called a contiguous array. Depending on the context and language I would call it "initialized" or "having only non-null elements" or similar to describe the contents.

Top 50 recent answers are included