Skip to main content

Contest 2 — A: Lantern Rows

Challenge on lesson: Contest 2-A: Lantern Rows

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** A street has n lamp posts in a row; some are lit ('L'), some dark ('D'). Every dark segment (maximal run of 'D') must receive ONE lantern anywhere inside it. Count the lanterns needed. **Input:** Line 1: n (1 <= n <= 200000). Line 2: the string of L/D characters. **Output:** One integer — the number of lanterns. **Example:** 7 / LLDDDLD -> 2.

Back to lesson: Contest 2-A: Lantern Rows