← Back to section

Final exam — String

Three unseen problems (not covered in the lessons) to test whether you leave this section able to solve any problem of the topic: one easy, one medium and one hard. Some test cases are hidden — like the real LeetCode. Solve in Python or JavaScript.

Easy

First Unique Character in a String

Given a string s, return the index of the first character that does not repeat. If there is none, return -1.

Example: s = "leetcode" → 0 (the 'l' is the first one that appears exactly once). s = "aabb" → -1.

Carregando editor…
Medium

Find All Anagrams in a String

Given two strings s and p, return a list of the starting indices of all anagrams of p within s (in increasing order).

Example: s = "cbaebabacd", p = "abc" → [0, 6] (the slices "cba" and "bac" are anagrams of "abc").

Carregando editor…
Hard

Longest Valid Parentheses

Given a string s containing only ( and ), return the length of the longest substring of valid parentheses (correctly closed).

Example: s = ")()())" → 4 (the substring "()()"). s = "(()" → 2.

Carregando editor…