You're given red blocks and green blocks where g. A tower of height uses exactly blocks total.
Since you must use all blocks, you need for some integer . First task: find the largest where this is possible. If doesn't equal a triangular number, no valid tower exists. Understanding the problem structure is half the battle.