Convert Identifiers Between camelCase, snake_case, and kebab-case
Last updated: November 29, 2026
Quick Overview
Write a function that takes an identifier in any common style (camelCase, PascalCase, snake_case, kebab-case, including acronyms like HTTP and digit runs) and rewrites it in a requested target style.
0
0
0 solved
Write a function that takes an identifier in any common style (camelCase, PascalCase, snake_case, kebab-case, including acronyms like HTTP and digit runs) and rewrites it in a requested target style.
Frontend and tooling interviews at Google sometimes use this as a practical parsing task, for example mapping proto field names to JavaScript property names. The interviewer is checking how you define word boundaries, especially around acronyms and digits, more than the joining step.
What the Interviewer Expects
- Defines word boundaries explicitly before coding
- Handles separators, case transitions, acronyms, and digit runs
- Separates splitting words from formatting the output
- Discusses ambiguous inputs such as plural acronyms
- Tests several styles in both directions
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Make the conversion round-trip safe for names like userIDs; what extra information do you need?
- How does protobuf map field names like foo_bar_2 to JSON names?
- How would you apply this rename across a large codebase safely?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: an identifier and a target style among
snake,kebab,camel,pascal. - Word boundaries: separators
_,-, whitespace; a lowercase-to-uppercase transition; the end of an acronym run ...
High-Level Design
Split the problem into two steps. First, tokenize into lowercase words, which is the only hard part. Splitting on separators handles snake and kebab input. Within each chunk, a regular expression with...