Real World Practice Questions in Python

1. First Non-Repeating Character

Problem Statement

Given a string s, find the first non-repeating character in it and return its index.
If no such character exists, return -1.

Example 1

Input: s = "edSlash"
Output: 0
Explanation: 'e' is the first non-repeating character.

Example 2

Input: s = "loveedSlash"
Output: 1
Explanation: 'v' is the first non-repeating character.

Example 3

Input: s = "aabb"
Output: -1
Explanation: All characters are repeating.

Constraints

  • 1 ≤ len(s) ≤ 10⁵
  • s consists of only lowercase English letters.

Function Signature

def firstUniqChar(s: str) -> int:
    pass

Hidden Test Cases

  • Single-character string: "z"0
  • All repeating characters: "aabbcc"-1
  • Mix of frequent and rare: "aabbccddeffg"10 ('g')
  • Long string with unique at start: "x" + "a"*999990
  • Long string with unique at end: "a"*99999 + "x"99999

2. Check for Anagram

Problem Statement

Given two strings s and t, return True if t is an anagram of s, and False otherwise.
An anagram is a word or phrase formed by rearranging the letters of another word, using all the original letters exactly once.

Example 1

Input: s = "listen", t = "silent"
Output: True
Explanation: Both words contain the same letters with the same frequencies.

Example 2

Input: s = "rat", t = "car"
Output: False
Explanation: Characters differ.

Example 3

Input: s = "edSlash", t = "dashSel"
Output: True
Explanation: Both strings use the same characters in different order (case-insensitive).

Constraints

  • 1 ≤ len(s), len(t) ≤ 10⁵
  • Strings can contain alphabets (uppercase/lowercase).
  • Comparison is case-insensitive.
  • You may assume no special characters or spaces.

Function Signature

def isAnagram(s: str, t: str) -> bool:
    pass

Hidden Test Cases

  • s = "a", t = "a" → True
  • s = "a", t = "A" → True
  • s = "abc", t = "abcc" → False
  • s = "Dormitory", t = "DirtyRoom" → True

3. Remove Duplicates from a List While Preserving Order

Problem Statement

Given a list of integers nums, remove all duplicates while preserving the original order of appearance.
Return the new list.

Example 1

Input: nums = [1, 2, 3, 2, 1, 4]
Output: [1, 2, 3, 4]
Explanation: Duplicates 2 and 1 are removed but order is preserved.

Example 2

Input: nums = [5, 5, 5, 5]
Output: [5]
Explanation: All elements are same.

Example 3

Input: nums = [10, 20, 10, 30, 40, 30]
Output: [10, 20, 30, 40]
Explanation: First occurrences kept in the same order.

Example 4

Input: nums = [1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6, 7]
Output: [1, 2, 3, 4, 5, 6, 7]
Explanation: Only unique sequence remains.

Example 5

Input: nums = ['e', 'd', 'S', 'l', 'a', 's', 'h', 'e', 'd']
Output: ['e', 'd', 'S', 'l', 'a', 's', 'h']
Explanation: For 'edSlash', duplicates 'e' and 'd' are removed while keeping the first occurrence.

Constraints

  • 1 ≤ len(nums) ≤ 10⁶
  • Elements can be integers or strings (you must handle both).
  • Maintain original order.

Function Signature

def remove_duplicates(nums: list) -> list:
    pass

Hidden Test Cases

  • nums = [][]
  • nums = [1][1]
  • nums = list(range(1000000)) → same list (no duplicates)
  • nums = [1, 2, 2, 3, 3, 3][1, 2, 3]
  • nums = ['a', 'A', 'a']['a', 'A'] (case-sensitive)