Answer: LEGRAND Hiring | Campus Interview Question | On-Campus OA (2025)
Answer · Posted Jun 2026
Approach The string is valid if it never contains the substring "ba". If "ba" exists, then an 'a' appears after a 'b'. Strategy Use the built-in contains() method. Return false if "ba" exists; otherwise return true. Java Code class Solution { public boolean checkString(String s) { return !s.contains("ba"); } } class Solution { public boolean checkString(String s) { boolean seenB = false; for (char c : s.toCharArray()) { if (c == 'b') seenB = true; if (c == 'a' && ...
The full answer & interview discussion are available to premium members.
Log in Create a free account