leetle

Daily challenge for 2026-10-08

646. Shelf Book Alternation

You are organizing a library shelf containing thin and thick books, represented by strings "T" (thin) and "K" (thick) in an array books.

A shelf arrangement is considered properly alternated if no two consecutive books are of the same thickness.

Return the minimum number of books you need to change (from "T" to "K" or vice versa) so that the entire row alternates.

Example:
Input: books = ["T", "T", "K", "K"]
Output: 2
Explanation: Changing the first "T" to "K" and the last "K" to "T" gives ["K", "T", "K", "T"], requiring 2 changes. Changing the second "T" to "K" and the third "K" to "T" gives ["T", "K", "T", "K"], which also requires 2 changes.

Run this challenge interactively in Python or JavaScript when the app loads.