Frage im Vorstellungsgespräch bei Wayfair

Given a string, return a boolean value if the strings contains matching brackets Example: Input: "This is [a valid] string" Output: True Input: "This is an [invalid string" Output: False

Antworten zu Vorstellungsgespräch

Anonym

12. März 2018

Use a stack data structure

2

Anonym

27. Mai 2018

function fun(){ $st = "This is [[a valid] st]ring"; $a = str_split($st); $brack_opens = array_keys($a,"["); $brack_close = array_keys($a,"]"); if(count($brack_opens)==count($brack_close)) return "true"; return "false"; } print(fun());

Anonym

27. Aug. 2018

That doesn't work. It would return valid for a string like this "This is ]]a valid[ st[ring"