SAP Interview Question. Help Needed

Правка en1, от Sumanto, 2020-06-24 09:39:54

There are two strings, s and t.

Perform two operations with string s:

  1. Working from Left-to-Right delete each occurance of t in s until there are no more occurances of t. Count each deletion.
  2. Working from Right-to-Left delete each occurance of t in s until there are no more occurances of t. Count each deletion.

Return Greater of the two counts.

Example: s="bcbbc" t="b" - From left To Right: s reduces to bcbbc->cbbc->cbc->cc, The number of moves is three - From Right To Left: bcbbc->bcbc->bcc->cc , The number of moves is three So ans is max(L-to-R,R-to-L)=3;

Example: s="aabb" t="ab" - From left To Right: s reduces to aabb->ab->"", The number of moves is two - From Right To Left: s reduces to aabb->ab->"", The number of moves is two So ans is max(L-to-R,R-to-L)=2;

Constraints: 1<=length(s)<=2*10^4 1<=length(t)<=100

snaps of the problem: https://imgur.com/a/uvOgvbh

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Sumanto 2020-06-24 09:39:54 954 Initial revision (published)