MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / getLast

Function getLast

javascript/0763-partition-labels.js:40–49  ·  view source on GitHub ↗
(S, lastSeen = [])

Source from the content-addressed store, hash-verified

38};
39
40const getLast = (S, lastSeen = []) => {
41 for (const index in S) {
42 /* Time O(N) */
43 const code = getCode(S[Number(index)]);
44
45 lastSeen[code] = Number(index); /* Space O(1) */
46 }
47
48 return lastSeen;
49};
50
51const getCode = (char) => char.charCodeAt(0) - 'a'.charCodeAt(0);
52

Callers 1

partitionLabelsFunction · 0.85

Calls 1

getCodeFunction · 0.70

Tested by

no test coverage detected