InterviewLegend

Strings & Sliding Windows

Alex Chen25 min readUpdated 330 real interview reports

Strings fill a good share of SAP's coding rounds, and the three problems here come from both the online assessment and the later technical rounds. One shape, the longest stretch of ones after k flips, appears in the Associate Developer online assessment and again under another name in a Software Developer technical round. Others come from a Scholar@SAP round, the third round of an SAP Ariba interview, and a second technical round that shared its forty-five minutes with Java questions about == and .equals().

Two of the three are sliding windows. A left and a right pointer bound a stretch of the string, the right one steps forward on every character, and the left one only ever moves forward too. What differs is the state. One counts zeros inside the window, and the other keeps the last index where each character appeared. The third compares columns across a list of words instead, and its usual follow-up asks when a trie built once over a fixed word list beats rescanning for every query.

Say why the left edge never moves backwards before you write the loop. Each index enters the window once and leaves it at most once, so two pointers crossing n characters cost O(n) however often the window grows and shrinks. In the last-seen-index version, the same rule guards against a stale-index bug, because a last-seen position already behind the left edge must never drag it back.

SAPPremium lesson · Coding round

The 3 SAP problems are below.

  1. A Premium questionCoding · Medium · Frequently asked
  2. A Premium questionCoding · Easy
  3. A Premium questionCoding · Medium

Each with hints, the follow-up and a tested solution.

Get the SAP questions

$49 a year · all 100 companies · cancel anytime

From 330 SAP reports, forum threads behind logins and write-ups in Chinese.

Had your SAP interview?Tell us what they asked. Reviewed before it goes in, never with your name.
SAP interview guide

Know what SAP asks before you walk in.

25 coding · 2 system design · 30 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.