Back to problems

Solve array duplicate flags and binary swaps

Algorithm · Salesforce · Medium

Problem 1: Flag duplicates on both sides Given an integer array arr, return an integer array flags with the same length. For each index i, set flags[i] = 1 when the value arr[i] appears at least once strictly to the left of i and at least once strictly to the right of i. Otherwise set flags[i] = 0. Indexing is zero-based. Example 1: Explanation: Only index 2 satisfies the condition because the value 3 also appears at index 0 and index 6. Example 2: Explanation: Indices 2, 3,…

Checking your access…