Magicsheet logo

Determine if String Halves Are Alike

Easy
25%
Updated 8/1/2025

Asked by 3 Companies

Determine if String Halves Are Alike

What is this problem about?

The Determine if String Halves Are Alike coding problem asks you to split an even-length string into two equal halves. You need to return true if both halves have the same number of vowels ('a', 'e', 'i', 'o', 'u', case-insensitive).

Why is this asked in interviews?

Amazon and Adobe use this "Easy" question to verify basic string manipulation and counting skills. It's a "cleanliness" test. It evaluations whether you can implement a solution without redundant code—for instance, by creating a helper function to count vowels rather than repeating the same logic for both halves.

Algorithmic pattern used

This is a simple Counting interview pattern.

  1. Define a set of vowels for O(1)O(1) lookup.
  2. Calculate the midpoint: mid = length / 2.
  3. Count vowels in the first half [0, mid).
  4. Count vowels in the second half [mid, length).
  5. Compare counts.

Example explanation

String: "book"

  1. Halves: "bo" and "ok".
  2. "bo": 1 vowel ('o').
  3. "ok": 1 vowel ('o').
  4. Counts match. Result: true. String: "textbook"
  5. Halves: "text" and "book".
  6. "text": 1 vowel ('e').
  7. "book": 2 vowels ('o', 'o').
  8. Result: false.

Common mistakes candidates make

  • Case Sensitivity: Forgetting to handle both uppercase and lowercase vowels.
  • Inefficient Sets: Checking vowels using a long if statement or a list, though for 5 vowels, the performance impact is negligible.
  • Midpoint logic: Off-by-one errors when slicing the string.

Interview preparation tip

Use a String or Set containing "aeiouAEIOU" and the .indexOf() or .contains() method to check for vowels. It makes your code much cleaner than using multiple || operators.

Similar Questions