Determine if String Halves Are Alike

You are given a string s of even length. Split it into two halves of equal length, a (the first half) and b (the second half). Two strings are alike if they contain the same number of vowels (a, e, i, o, u, in either case). Return true if a and b are alike, and false otherwise.

30:00

Determine if String Halves Are Alike
easy
Free written solution
Topics
Companies

You are given a string s of even length. Split it into two halves of equal length, a (the first half) and b (the second half). Two strings are alike if they contain the same number of vowels (a, e, i, o, u, in either case). Return true if a and b are alike, and false otherwise.

Example 1:
Input: {"s":"book"}
Output: true
Constraints:
  • 2≤s.length≤10002 \leq \text{s.length} \leq 1000

  • s.length is even.

  • s consists of uppercase and lowercase letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"book"}

len(s) = 4, so cut it at half = 2: a = "bo" and b = "ok".

s (length 4) is about to be cut in the middle

b
o
o
k

vowel scale

a: 0

b: 0

balanced: 0 = 0

Variables
VariableValue
half2
DepthFunction Call
Stack empty
0/4