Answer: GRUNDFOS Hiring Challenge | Count Asterisks | Off-Campus OA (2025)

Answer · Posted Jun 2026

Approach Traverse the string from left to right. Maintain a boolean variable indicating whether the current position is inside a pair of |. Toggle the boolean whenever | is encountered. Count * only when outside the | section. Strategy Initialize inside = false. Iterate through every character. Toggle inside when | is found. Count * only if inside is false. Return the total count. Java Code class Solution { public int countAsterisks(String s) { boolean inside = false; int count ...

The full answer & interview discussion are available to premium members.

Log in Create a free account