DevelopmentAugust 9, 2026· via DEV Community

Weekly coding challenge: slicing parentheses and rare words

Weekly coding challenge: slicing parentheses and rare words

Image : DEV Community

The latest Weekly Challenge brings two neat tasks for programmers: one to spot words that appear only once across two sentences, and another to peel away the outer layer of nested parentheses. Both are designed to test string manipulation skills without heavy dependencies.

## Task 1: Counting the lonely words

The first puzzle asks solvers to return all “uncommon” words—those that occur exactly once when two sentences are combined. A Python solution uses collections.Counter to tally frequencies and then filters for the count of one. Because Python 3.6+ dictionaries preserve insertion order, the output keeps the same sequence as the input sentences. For Perl, which does not guarantee hash order, the author sorts the unique words alphabetically before returning them.

## Task 2: Trimming the outermost parentheses

The second challenge takes a valid parentheses string and removes the outermost pair from every primitive substring. A simple loop tracks how many open parentheses remain unclosed; characters are added to the result only when they are not the outermost layer. Extra checks ensure the string starts and ends correctly and that parentheses are balanced.

Why it matters

These tasks sharpen core string-handling skills that show up in parsing, logging and data-cleaning pipelines. The rare-word filter is useful for deduplication, while the parentheses parser is a miniature version of bracket-matching logic used in compilers and configuration parsers. For readers, tackling both in one sitting is a quick way to reinforce clean iteration and state tracking.

The Weekly Challenge Challenge write-up


Source: DEV Community. AI-assisted editorial synthesis — TechnoExpress.

Read the original source on DEV Community →

← Back to home