Twitch Interview Question

Given this single API and an unlimited (space) input buffer, show how you would replace space characters with URL-encoded “%20”. void replaceSpaces(char *buffer); That is: “Hello World Twitch” would become “Hello%20World%20Twitch”

Interview Answers

Anonymous

Jan 26, 2021

There's a lot of elements to typically cover in these questions, clarifications, scoping, making sure you're answering the actual question the interviewer is looking for you to answer, etc. Could be worth doing a mock interview with one of the Prepfully Twitch IOS Engineer experts... they've worked in the role so they clearly know how to get through the interview. prepfully.com/practice-interviews

Anonymous

Apr 19, 2017

void replaceSpaces(char *buffer) { int numberOfSpaces = 0; int index = 0; if(buffer == NULL) return; // 1 - count the number of spaces we need to care about while(buffer[index] != 0) { if(buffer[index] == ' ') numberOfSpaces++; index++; // picks up the null terminator at the end } // 2 - move the bytes along from the back to the front for( ; index > 0; index—) { if(buffer[index] == ' ') { buffer[index] = '%'; buffer[index+1] = '2'; buffer[index+2] = '0'; numberOfSpaces - 1; } else { buffer[index+(numberOfSpaces * 2)] = buffer[index]; } } }