SShortSingh.
Back to feed

Two Python approaches to solving LeetCode's Remove Duplicates from Sorted Array

0
·1 views

LeetCode's 'Remove Duplicates from Sorted Array' problem requires modifying a sorted integer array in-place so each unique element appears only once, returning the count of unique elements. Two Python solutions are demonstrated: a pop-based approach that removes duplicate elements directly, running in 57ms, and a faster head-pointer method that overwrites duplicates by shifting unique values to the front, running in just 7ms. Both solutions use approximately 13–13.7MB of memory. The head-pointer approach is more efficient because it avoids the overhead of repeatedly resizing the array. A key insight is that elements beyond index k-1 do not need to remain organized, as the problem explicitly states they will be ignored.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

How to Build a Confidential OTC Settlement Protocol Using Oasis Sapphire and Base

A new developer tutorial on DEV Community walks through building a privacy-preserving over-the-counter trading protocol for large cryptocurrency transactions. The protocol combines confidential smart contract execution on Oasis Sapphire with transparent on-chain settlement on Base, an Ethereum Layer 2 network. It addresses a core challenge in decentralized finance: large trades executed through public liquidity pools expose sensitive order information to arbitrage bots and market participants, distorting prices. Oasis Sapphire enables confidential negotiation between counterparties directly within an EVM-compatible environment using standard Solidity code, keeping deal terms private until settlement. The tutorial covers key features including encrypted trade offers, private counterparty quotes, asset escrow, replay-attack prevention, and safe order cancellation.

0
ProgrammingDEV Community ·

Why temperature=0 Does Not Make AI Agents Deterministic and How to Test Them

A technical article on DEV Community explains why AI agents can produce different outputs even when temperature is set to zero, a setting commonly assumed to eliminate randomness. The variation stems from floating-point arithmetic on GPUs, request batching by model providers, and infrastructure changes such as hardware swaps or model re-quantization. Tests that rely on exact string matching therefore fail intermittently even when the agent is functioning correctly, eroding developer trust in test results. The article recommends shifting assertions away from literal text matching toward verifying output structure, required fields, data types, and valid values. Using JSON Schema validators like Ajv is proposed as a practical approach to writing resilient, semantics-focused tests for non-deterministic AI systems.

0
ProgrammingDEV Community ·

How Developers Can Build a Reusable Crypto Payment Kit for Agencies to Resell

A new blueprint outlines how developers can create a 'Merchant Crypto Launch Kit' — a packaged system that agencies can resell to their merchant clients instead of building one-off crypto payment integrations each time. The kit can include checkout flows, webhook handling, branded payment pages, onboarding documents, and support playbooks, giving agencies a standardized delivery system. Agencies are seen as the ideal channel because they already manage client websites, ecommerce stores, and SaaS products but often lack the expertise to handle crypto payment infrastructure themselves. The guide uses OxaPay as its reference infrastructure, citing its support for hosted invoices, white-label payments, static addresses, payout APIs, and automation integrations. The core argument is that selling a repeatable system to agencies is more scalable and commercially viable than selling individual integrations directly to merchants.

0
ProgrammingDEV Community ·

How a Misrouted S3 Worker Almost Handed a Startup a $30,000 AWS Bill

A startup came within 48 hours of receiving a $30,000 AWS invoice after a worker process fetched millions of small JSON files from S3 through a NAT gateway, which charges for every byte of data it routes. The NAT gateway, sitting between the company's private subnet and the internet, silently metered all traffic without any obvious warning to the engineering team. The fix required no application rewrite — adding a VPC gateway endpoint for S3 rerouted traffic through AWS's private network, eliminating the costly NAT charges entirely. The incident highlights a broader cloud cost trap: small-file workloads at scale generate disproportionate per-request overhead, and cross-AZ or NAT-routed traffic can quietly drain budgets. Engineers are advised to trace the physical path of data traffic before scaling any data-moving workload, since intra-region endpoint-routed traffic is often free while NAT-routed traffic is not.

Two Python approaches to solving LeetCode's Remove Duplicates from Sorted Array · ShortSingh