Skip to content
Katabench
Try free

One Sale, Two Business Days

Medium About 10 min Free, no account needed

During a terminal rollout, the same moment in the same shop landed on two different business days, and evening takings started drifting into tomorrow.

The brief

Reported by: Store operations, Tokyo Impact: Since the new terminals started rolling out, evening takings at some stores land on the next day's report and the daily cash count no longer balances Code: DailyTakings in the store reporting job

What the stores see

Two terminals in the same shop rang up identical sales at the same moment, shortly before closing on March 14. The report filed one under March 14 and the other under March 15. The shop closed at 23:00 local time, so March 14 is the right answer for both.

Log excerpt

Text
takings 22:40:03 store=TYO-4 offset=+540 terminal=T-11 fw=3.8  stamp=2026-03-14T13:40:00Z      cents=1250 day=2026-03-14
takings 22:40:05 store=TYO-4 offset=+540 terminal=T-12 fw=4.0  stamp=2026-03-14T22:40:00+09:00 cents=1250 day=2026-03-15
takings 09:15:44 store=TYO-4 offset=+540 terminal=T-12 fw=4.0  stamp=2026-03-15T09:15:00+09:00 cents=800  day=2026-03-15
takings 10:00:07 store=TYO-4 offset=+540 via=gw-chi            stamp=2026-03-14T20:00:00-05:00 cents=400  day=2026-03-15

What we know so far

  • Store operations blames clock drift on the new terminals.
  • Sales from new terminals earlier in the day land on the right date, which is how the rollout passed its smoke test.

Your job

Fix DailyTakings so a sale lands on the store's local business day, however its timestamp is written. Each sale is TIMESTAMP|CENTS, and each row returned is yyyy-MM-dd CENTS, earliest day first. A store's distance from UTC is the fixed storeOffsetMinutes, so no time zone database is involved.

Working the incident

The visible tests all pass, because this bug shipped. A hidden regression suite replays the incident and its neighbours. Custom input replays a log line, and anything you write with Console.WriteLine shows up in the results.

Starter code

C#
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

public class Solution
{
    // sales: "<ISO 8601 timestamp with offset>|<cents>".
    // storeOffsetMinutes: the store's fixed distance from UTC, east positive.
    // Returns "yyyy-MM-dd CENTS" for each business day of the store, earliest first.
    public string[] DailyTakings(string[] sales, int storeOffsetMinutes)
    {
        var takings = new SortedDictionary<DateTime, long>();

        foreach (var sale in sales)
        {
            var parts = sale.Split('|');
            var stamped = DateTimeOffset.Parse(parts[0], CultureInfo.InvariantCulture);

            var utc = stamped.DateTime;
            var storeTime = utc.AddMinutes(storeOffsetMinutes);
            var businessDay = storeTime.Date;

            takings.TryGetValue(businessDay, out var soFar);
            takings[businessDay] = soFar + long.Parse(parts[1], CultureInfo.InvariantCulture);
        }

        return takings
            .Select(day => $"{day.Key.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)} {day.Value}")
            .ToArray();
    }
}

How it is graded

Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.

C# coding challenges →

Related guides

What it practices

Debugging from symptoms
Work from a production symptom and a log excerpt back to the cause, then fix it without breaking what already works.

Related katas