Skip to content

Instantly share code, notes, and snippets.

Coding Problem 1 — Two Sum

Estimated time: 15 menit Bahasa: Bebas (Go, Node.js, TypeScript, Python, dll — pilih yang paling nyaman)


🧩 Soal

Bayangkan kita punya sistem reconciliation di payment gateway. Setiap hari kita dapat list transaksi, dan kita perlu cari pasangan transaksi (debit & credit) yang nominalnya kalau dijumlah persis sama dengan target settlement amount.

At a ticketing company, we manage massive live events. Imagine we have a stadium with $n$ seats, numbered from 1 to $n$. All seats are initially unreserved. We need to implement a SeatManager class that efficiently handles the reservation and cancellation of these seats in real-time.

Requirements:

  1. SeatManager(int n): Initializes a SeatManager object that will manage $n$ seats numbered from 1 to $n$.
  2. reserve(): Fetches the smallest-numbered unreserved seat, reserves it, and returns its number.

🧩 Live Coding Challenge — Support Ticket Desk


🕐 Duration

30–60 minutes (live session)

🎯 Objective

🧮 Coding Challenge — Hitung Total Harga Keranjang

Soal

Buat fungsi calculateTotalPrice(cart) yang menerima array berisi objek dengan struktur:

{ name, price, quantity }

Real-World Challenge: “Safe Cached Ticket Counter”


🧩 Konteks

Kamu membangun endpoint POST /buy untuk sistem ticketing. Jumlah tiket per event terbatas (misalnya 1,000 tiket). Service kamu berjalan di Kubernetes multi-pod, dengan Redis shared cache, dan database PostgreSQL sebagai sumber kebenaran.

💻 Coding Challenge — POST /buy (Moflip Ticketing)

🎯 Tujuan

Implement POST /buy yang mengunci dan mengurangi kuantitas tiket secara aman di lingkungan multi-pod tanpa oversell.


🧱 Asumsi Lingkungan

import asyncio
import os
from concurrent.futures import ThreadPoolExecutor
import PySpin
BUFFER_SIZE = 1500
NUM_IMAGES = 4000 # The number of images to capture
NUM_SAVERS = 100 # The number of saver coroutines
# The directories to save to camera i will save images to SAVE_DIRS[i]
SAVE_DIRS = ['K:/Google Drive/Katz-Lab_Otter-Data/Projects/3D-Behavior/code/Test1','K:/Google Drive/Katz-Lab_Otter-Data/Projects/3D-Behavior/code/Test2']
# =============================================================================
# Copyright (c) 2001-2020 FLIR Systems, Inc. All Rights Reserved.
#
# This software is the confidential and proprietary information of FLIR
# Integrated Imaging Solutions, Inc. ("Confidential Information"). You
# shall not disclose such Confidential Information and shall use it only in
# accordance with the terms of the license agreement you entered into
# with FLIR Integrated Imaging Solutions, Inc. (FLIR).
#
# FLIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
Stream Buffer Count Mode set to manual...
Default Buffer Handling Mode: Oldest First
Default Buffer Count: 10
Maximum Buffer Count: 4308
Buffer count now set to: 3500
Now Buffer Handling Mode: Oldest First Overwrite
Stream Buffer Count Mode set to manual...
Default Buffer Handling Mode: Oldest First
NUM_IMAGES = 4000 # The number of images to capture
NUM_SAVERS = 10 # The number of saver coroutines
BUFFER_SIZE = 3500
# Set up cam_list and queue
system = PySpin.System.GetInstance()
cam_list = system.GetCameras()
queue = asyncio.Queue()