Loading…
Loading…
The raffle printer has hiccups. Any number it prints more than once is disqualified, a ruling the owner of seventeen identical tickets intends to appeal. Read tickets in print order and return the zero-based index of the first ticket whose number appears exactly once in the entire list. Return -1 if the prize marmalade goes unclaimed.
[12,7,12,9,7,4]Output39 and 4 each appear once, and 9 comes first, at index 3.
[0,8,8]Output0The ticket numbered 0 appears once, so the answer is its index, which is also 0.
Treat counting and choosing as two separate steps. Once you have counted every number, how do you find the first one in the original order?
/** @param {number[]} tickets * @returns {number} */ function solve(tickets) { // Find the first number that occurs exactly once. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.