iGoodie's Solution
@iGoodie
7 months ago

Thoughts

Approach

Code

type CharArray<T extends string> = T extends `${infer First}${infer Rest}` ? [First, ...CharArray<Rest>] : []; type FirstUniqueCharIndex< T extends string, $chars = CharArray<T>, $index extends number[] = [], $ignore extends string = "", > = $chars extends [infer First extends string, ...infer Rest] ? First extends Rest[number] ? FirstUniqueCharIndex<T, Rest, [...$index, 1], $ignore | First> : First extends $ignore ? FirstUniqueCharIndex<T, Rest, [...$index, 1], $ignore> : $index["length"] : -1; type a = FirstUniqueCharIndex<"leetcode">; // ^? type b = FirstUniqueCharIndex<"loveleetcode">; // ^? type c = FirstUniqueCharIndex<"">; // ^? type d = FirstUniqueCharIndex<"aabb">; // ^?
Loading...
Loading...