-
Find First and Last Position of Element in Sorted Array
Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1] Example…
-
Continuous Subarray Sum
Given an integer array nums and an integer k, return true if nums has a good subarray or false otherwise. A good subarray is a subarray where: Note that: Example 1: Input: nums = [23,2,4,6,7], k = 6 Output: true Explanation: [2, 4] is a continuous subarray of size 2 whose elements sum up to 6. let’s break down this code visually. The goal is to…
-
System Design – Polling system
Designing a system to handle a real‐time vote during a Super Bowl commercial—30 million votes cast in maybe 30 seconds (≈1 million votes/sec!)—requires careful attention to scalability, low latency, and resiliency. Here’s one possible end-to-end architecture: 1. Traffic Profile & SLAs 2. Ingestion Layer 3. Stream Buffering 4. Real-Time Aggregation 5. Persistent Storage 6. Front-End…
