Question bank › Hashing
Dsa Hashing Easy

Weighted Bucket Sharding

Implement a basic sharding hash. For a string S, the hash score is calculated as: Sum of (ASCII value of character * (1-indexed position)). The bucket is (score % B). Given a list of strings and the number of buckets B, find which bucket ID (0 to B-1) receives the most strings. If there is a tie, return the smallest bucket ID. Input Format: - Line 1: N (number of strings) and B (number of buckets). - Next N lines: One string per line. Output Format: - The integer ID of the busiest bucket. Example: Input: 3 2 hi bye no Output: 1 (Explanation: 'hi' -> (104*1 + 105*2)=314. 314%2=0. 'bye' -> (98*1 + 121*2 + 101*3)=643. 643%2=1. 'no' -> (110*1 + 111*2)=332. 332%2=0. Bucket 0 has 2, Bucket 1 has 1. Busiest is 0. Wait, math check: 314%2=0, 332%2=0. Correct.)

Key concepts

hashingimplementationdistribution

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.