SShortSingh.
Back to feed

Sliding Window Technique: Concepts, Examples, and Practice for Coding Interviews

0
·4 views

The sliding window technique is an algorithmic method for problems involving contiguous subarrays or substrings, and interviewers often ask about it to gauge a candidate's skill in optimizing time and space complexity. It uses two pointers to mark the start and end of a dynamic window that grows or shrinks as the data is traversed. By avoiding redundant checks, the approach can cut running time from roughly O(n^2) to O(n). The article illustrates it with a function that finds the longest substring without repeating characters, tracking characters in a set and shrinking the window when duplicates appear. It also covers how to decide when to adjust the window and where the technique does not apply.

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 ·

Checking new mail is not task management: give each email an ID and track it

A series on running a small business with AI employees argues that a daily report of new emails is not enough to manage work. An AI assistant that only lists mail arriving since its last check will drop an email after one report, even if nobody has replied, so a deadline can vanish. The author recommends giving each email that needs action an ID, turning it into a task, and showing it every morning until it is marked done. The approach was tested with a short program and two sample emails, not a real inbox, and no AI was involved in reading the mail.

0
ProgrammingDEV Community ·

Why a compromised inbox can undermine account recovery and what to check

Password reset links are sent to email, so an attacker who controls an inbox may gain a second route into linked accounts. The article notes that reusing an old password on a forgotten service can turn a small breach into a larger recovery problem. It recommends unique passwords for primary and backup email, passkeys or security keys where possible, and regular review of active sessions and forwarding rules. It also suggests storing recovery codes separately and testing reset behavior in a controlled environment, including whether old sessions and reset links remain valid.

0
ProgrammingDEV Community ·

Browser-Based Golf Ballistics Engine Computes Carry Without Uploading Launch Data

A developer building the Club Carry tools argues that most online golf distance charts oversimplify ballistics with a linear multiplier and require users to upload launch monitor data to third-party servers. The project instead runs all calculations client-side in vanilla JavaScript ES modules, with no dependencies and no server uploads, including parsing of Garmin R10 and Rapsodo MLM2PRO CSV exports. The model anchors carry to ball speed using reference averages from TrackMan's 2023 PGA and LPGA Tour data, since carry per mph rises as ball speed increases. It then applies empirical strike-quality tiers to estimate carry for amateur golfers across several swing speed bands. A binary search inverts the nonlinear 7-iron carry model back to an estimated driver clubhead speed in microseconds.

0
ProgrammingDEV Community ·

Keeping Seller Order Email Templates in the FastAPI App Under Three Review Gates

The article argues that a marketplace's transactional email templates should be owned by the application rather than a hosted editor when the backend must control which order data reaches an outside processor. Template changes can silently widen the data sent to a processor, so each message needs an approved template, approved destination, and approved data fields. Recommended practice is a versioned template paired with an explicit field allowlist, such as an order reference and a dashboard link for seller notifications. Before routing real seller data, teams must confirm where rendering and retention occur, who receives the data downstream, and how deletion covers each copy. The piece also presents one REST API provider as a fit for polling-based workflows, while noting it is unsuitable where instant delivery-triggered reactions are required.