
Google Software Engineer OA (Codility platform, 60 minutes, supports Python/Java/C++) consists of two programming questions, this article reproduces the meaning of the questions, analyzes the ideas, and shares the remote tutoring experience and preparation suggestions.
Topic 1: Minimum number of changes for rewording
meaning of a title
given string s
, which can be modified one character at a time. Ask the minimum number of modifications that can be made to the rearrangement of characters for the palindrome string.
Key observations
- To be able to be rearranged into palindromes: a maximum of one character is allowed to appear an odd number of times, the other characters need to have an even number of times.
- Counts how many characters appear an odd number of times
odd_count
, which needs to be altered only once for every two odd pairs.
formulas
cost = ⌊odd_count / 2⌋
typical example
importation "aabcd"
→ frequency a:2 b:1 c:1 d:1 → odd_count=3 → cost=⌊3/2⌋=1
Topic 2: Total number of modifications for all substring palindromic rearrangements
meaning of a title
given string dna
In this case, we enumerate all substrings, calculate the modification cost in topic 1 for each substring, and finally return the sum.
typical example
"abca"
→ sum of modification costs of all substrings = 6"wwwww"
→ all are themselves rearrangable as palindromes, sum = 0
Violent Method Complexity
O(n³) (n² enumerated substrings × O(n) statistical frequency), n ≤ 2 × 105 It was unacceptable at the time.
Optimization Ideas
- Quickly get the frequency of any substring character using a prefix count array
- Combine sliding window or hashing tricks to reduce odd_count computation per substring to O(1)
- Target complexity: O(n²) or better
Core Code Example (Topic 1)
from collections import Counter
def palindrome_transform_cost(s: str) -> int.
freq = Counter(s)
odd_count = sum(v & 1 for v in freq.values())
return odd_count // 2
# Test
print(palindrome_transform_cost("aabcd")) # 1
print(palindrome_transform_cost("aaaabbbb")) # 0
Remote Assistance Experience
I completed the OA pre-test two rounds of simulations through Programhelp's untethered remote voice + on-line coaching mode:
- Multi-pointer, greedy strategy walkthrough
- String boundaries and input/output details
- Python Quick Coding Tips
In the formal OA, my tutor only gave me micro-prompts by voice when I was stuck, which made the process smooth and did not interfere with my thinking, improving my efficiency and confidence.
Exam preparation advice
- Brush LeetCode Medium (arrays, strings)
- Practice common OA question sets
- Do more 1v1 mock (preferably with voice + online environment)
- Practice reading speed and boundary condition handling
Google OA requires you to output clear and complete solutions to common problems in less than 30 minutes. A combination of professional simulations and remote tutoring can help you do more with less!
-- Good luck with OA.
For one-on-one simulations and remote coaching, feel free to Contact Us.