Watch a technical mock interview with a Snowflake engineer
Supreme Kraken, a Snowflake engineer, interviewed Stealthy Hawk in Python
Share
Summary

Problem type 

Decode string

Question(s) asked 

Given an input string such as 'a2b3c4' produce an output string like 'aaabbbbccccc'

Feedback

Feedback about Stealthy Hawk (the interviewee)

Advance this person to the next round?
  No
How were their technical skills?
2/4
How was their problem solving ability?
2/4
What about their communication ability?
2/4
You need to practice more but you are almost there. All the best for your next one. Explain the approach before jumping on coding.

Feedback about Supreme Kraken (the interviewer)

Would you want to work with this person?
  Yes
How excited would you be to work with them?
4/4
How good were the questions?
4/4
How helpful was your interviewer in guiding you to the solution(s)?
4/4
The interviewer was very patient and helpful, offering useful hints and advice when I was stuck.
Transcript
Stealthy Hawk: Hello. Supreme Kraken: Hi, can you hear me? Stealthy Hawk: Yeah, yeah, I can hear you. Thank you so much for joining today. Supreme Kraken: All right, yep. Thanks to you as well. So yeah, let's get this started, I think we will have you know, that little introduction don't need to disclose your identity. But I will start with myself. So I am working in Seattle area as a senior Big Data Platform engineer, and, you know, like, I have 15 years of experience. You tell me about yourself, what do you have expectation of this exercise? And then, what do you want to achieve? Stealthy Hawk: Yes, thank you. I'm from San Francisco Bay Area. And I'm a recent university graduate. My background is mostly in engineering. And I'm just looking for my first job in the industry. And for that, I want to practice coding interviews and I'm get very good at them. But I'm not very fast just yet. Supreme Kraken: Awesome. Which languages do you choose? Do you know? Stealthy Hawk: Like, for the programming, I only know Python. Supreme Kraken: We can get started. So this is the input of a string, and then I want the output to be printed like this. Stealthy Hawk: Okay. Oh, I see. So we have letters, and then the number that's followed by the letter signifies the amount of how many more times this letter will appear in our output string, because A2 means three As. Z2 translates into three Z's and B4 translates into four B's. Okay. Okay, let's start writing a function. So this function will take an input, something like our input string. And it's expected to after some operations expected to return an output string. So now we have to create a roadmap of how to get there. Let's see if we can loop through that string. First of all, we can convert that string into a list, so it's a little bit easier to iterate over it. And for that, we can split the string using str split. Let me get started on that. I'm not sure if it was the exact syntax, but what I'm trying to achieve with a line of code is to split up those characters. Supreme Kraken: Yeah, then, you can just remove the string equal to and then use like is a string input a string are displayed. And then that will split whatever you want to do it, and then you can print it because, you know, you want to remember everything. So if you feel like you want to see the result of this one, you can put it into the variable. Stealthy Hawk: Okay, so... Okay, I can let me create an input string just to test first. So this would be our input string. Let me comment this out first. Oh, it says empty separator. Oh, I see... Maybe like this. Great. Great. Okay. So let's uncomment this. And so this got returned as a list by default. Or I wonder if I need to convert it to the list using the syntax. Supreme Kraken: Why do you want to convert this into a list? Stealthy Hawk: To iterate over it? It's a little bit easier to iterate over a list using the for loop. Supreme Kraken: There should not be any difference iterating over the list or string. You can iterate over a string as well. Stealthy Hawk: Okay, yeah, yeah, you're right sorry. Okay. I should probably save it into a variable. So poor. Cool. And now we can create a conditional statement, which when it iterates over the string, it compares, if it's if it's a letter or a number. So if it has a letter, we'll move on to the next character. And if the character is a number, we compare it to this previous character and return number of characters corresponding to a number. So let me write some placeholder code just to get started on this. Okay. So this is a time when we compare this item to previous items. So we will address the elements of this array by index. So it would be something like... Something like this and we compare it. So, this is how we would address a character with a subsequent character by index of its position in the array. Supreme Kraken: No I'm sorry, I don't understand what is i here? Stealthy Hawk: Just the number of the place that the character takes in this array. Supreme Kraken: So, what would be the value of i? Stealthy Hawk: Value of i would be the index of the elements place and here it would be like the current position and here will be the next position. Okay if item is a string string. So we have to look at the value of an item if item happens to be an integer... And I will have to find a way to somehow address the previous element if we do that. So, I have to get the value of this item which happens to be an integer. So, it would be out equals item. Item times... there has to be a better way of addressing a preceding character. Supreme Kraken: So what do you want to you want to check the next character or the previous character? Stealthy Hawk: Previous character because what it appears to be based on the input output sequence, see A2 many this character will be followed by two A's so I just have to take this two and return two of those A's after the first A. Supreme Kraken: Then you can be you can do that by using the i minus one right that will be the previous character? Stealthy Hawk: Yeah, yeah. So it would be item multiplied by something like my string of the i minus one type of thing. So this is our item which is integer. So we take it and multiply it. But we cannot multiply string by an integer. Let me test something out. I just don't remember the sequence works. So, if I have like at least a five just comment this out for a moment. Supreme Kraken: So, what are you trying to do here? Stealthy Hawk: I'm trying to see if multiplication will return five A's. Supreme Kraken: So for that one first of all you need to have this and then we like to convert that into integer and then try to run it now. Stealthy Hawk: Oh, Okay, perfect. So now our item two and item and my string of five minus one. And we also look at also create an empty list that we would append to. And now, so, it so now we have to figure out what to append to this output stream. So, it would be... we'll have to append that character that we had before, and then the amount of characters that were multiplied by an integer. So, it's that some string, but it's just a just a pseudo code for right now. Supreme Kraken: Okay. So can you try to run a use case where you pass the input a string and then output and see if it is looking fine? Stealthy Hawk: Yeah, yeah. Let me just try this first. Let's just see what it returns. Let me test out this function. Oh, two separate. Oh, that's right. It returns an empty list. So my return statement could be indented incorrectly. Or there's something wrong with the for loop. Supreme Kraken: Can you try to debug? Stealthy Hawk: Yes. Oh, if item is a string, we have a way, instead of continuing, we should, we should return that string, we should append that string to the output string. Append this item. Now that it's appended, and then afterwards, we can continue, because the moment that says a string of the loop might stop executing on this first character, so my prediction is this, this code would probably return just a, because it would find the string and append it to the empty list. And it would return the list a, so we need a continue clause after this. Okay, it still returns an empty string. Maybe the return statement is out of place. It returns none. Okay, I'm a little bit stuck, I'm not sure... Supreme Kraken: Okay. So, let's print out this one and see what it is doing okay? So, it has been interviewed this which means this will consider as a single character, because if it is going in the list if you look through this list, it will only work for i zero because this is all in a single word right? Oh yes. And then if you... so you're running here in for my this things right? If I run for item in inputstring. Okay. And then I say print item, they will this one. So you know that what is happening and then. So then you are treating one character at a time. So what is the what is the what is the harm in you know, like iterating through the string itself, instead of you know, like converting this into anything into the string. You know what I'm saying you want to read to a to z to be full, right? Yes. So you don't need to do actually this my string you can directly do per item in input string, and then it will iterate through. Stealthy Hawk: Oh, okay, that's my comment this out. So input string, instead of input string. Yeah, this is not necessary either. Oh, yeah. So instead of, we'll have to wrap to get rid of the my string. You so it looks like it's printing out this. Supreme Kraken: Yeah, so this, you don't need to dictate through twice. So let's I am removing this input a string, this one. So now. Yes, now you have this. But I mean input a string and then what you are doing is you're saying if item is a string... What do you mean by the item is a string a string is a type so what what are you trying to check here? Stealthy Hawk: Oh, yeah, string, I shouldn't be calling it a string. I'm trying to determine if it's just like a character sets. And, or if it's an integer or not an integer. Supreme Kraken: Okay, so, and we can do so, if you want to check this item that you can say that if item isnumeric. Stealthy Hawk: Yes, exactly. Thank you. I forgot about that syntax. Yeah, if item is numeric, then we just... Oh, wait, no. Supreme Kraken: Actually, you want to you want to append you want to append when the item is not numeric, which means it is you know, like character alphanumeric, right? Yes. Okay, and then also in the output the string, why do you have list you want to return as string. Yeah, so take a look on that. Stealthy Hawk: Oh, yeah. Because like output string is right now in the list format. So this would return a list. But we don't want the list to be returned. So I can just... Can I do like an empty string? Supreme Kraken: Yeah, you can use it as an empty string. Stealthy Hawk: Okay, and are we allowed to append two strings? I believe append is only the list operation. Supreme Kraken: Yeah, append is not allowed into the string. So how you will add that history? Stealthy Hawk: I would concatenate empty string and that your string so I would do output string just plus. So output string it would be plus equals out. Okay, so have the empty string. Let me check what this code returns. So, output string... Well, there plus equals item and then we continue. Okay, well it doesn't return an error anymore. But the code doesn't do what we want it to do. It just eliminated numbers and duplicates. So it's somewhere that you were... Supreme Kraken: And why do you have this continue? Why do you need this continue? Stealthy Hawk: Because I was afraid that would the loop would stop executing on the first character, but now that I'm thinking about it, it would only be the case if it was a list. So, we might not need that... Supreme Kraken: Let's remove that, but that will not resolve your issue which you are facing. So, then what is happening here is you loop through and then wherever it is finding the character, so you found it, it loops through the list here, but item is put a string so it is loop through found a it is not numeric, which means is executed. So if this statement will take that one, put it into the output distinct when it comes to two. I don't know what you're doing here in the elif statement. And then why it is an elif statement. Because you have either character or non character. Oh, then we can just do the else statement, which was so then it. Yeah, so then it went to Z and did the same thing and did four. So that is where you are output issuing a Z and B, which means it is ignoring the numeric value. So I don't know why you have a elif statement. And then what do you mean by item is in? Stealthy Hawk: If it's integer, yeah, I should just write it as the else statement. Because if not numeric, the else statement would automatically mean that item is numeric. So instead of that, and you can use this. Supreme Kraken: Okay, so that is correct. Stealthy Hawk: Oh, my string is sorry about that. Because it doesn't recognize that i because it's not a list. So to refer this to the strings based on the position of their characters. Supreme Kraken: Do you know how you can look through the index as well as the item? Because here you are not looking through the index, you're looping at the item? Doesn't matter whether it is a string or list. Have you heard about enumerate? Stealthy Hawk: Oh, enumerate? Yeah, but it gives the index and the item. Supreme Kraken: Yeah, so let's take that one. And let's take the is an index an item. What do you want to try out? Stealthy Hawk: Yes, so if item is not numeric, then we add our item to our empty output string. But then otherwise, if item is numeric, then we take then we just take our item, then we just take our item, and we'll multiply it by i would take an item so we're multiply our item by the value. Supreme Kraken: What are you trying to do. Stealthy Hawk: I'm just trying to multiply the preceding letter by that number. Supreme Kraken: So what do you are getting here that we will have here on our end item, but it will be replaced here you know? Stealthy Hawk: I'm not entirely sure because I thought it would convert. Supreme Kraken: So let's go through this. Let's go through this iteration. So for I item so I become 0 first time an item become your first character which is a in this list right in this district. Yes. And then you are saying if not item is numeric, then add into your output history note for distinct you have defined here. So, then it found a and then executed this one right and then it moves to the next item which is i become one and then item becomes two, then you are saying that out? I don't know what is that okay. So, you are having out integer two, so that is two and then output is string you can do i minus one because i minus one is you know like the before two it is a so the previous character you want to multiply if you multiply the previous character, that is what you want to do. So then it will do to a and then you already have a run into our for the string, which will have this one. So if you run this unit, you have your output. Stealthy Hawk: Oh yeah, yeah. Supreme Kraken: And then you might not even need I don't know whether you want to do this way or you can just remove this like this is letter. All right, fine. Yeah, that is how we will do I would my suggestion would be to you to do more practice. And also before jumping and solving the problem, like understand the problem, discuss the problem and then proceed and then let the interviewer know that what you are doing so that both of them are on the same page. Because in this study, I had trouble understanding that no, like what you want to do, but yeah, I mean, you need to do a lot of practice. I will say this, everybody start from a place and I understand that you are a college graduate, but yeah. Stealthy Hawk: Thank you so much. I've been doing leetcode, but I'm just very new to this. Supreme Kraken: Awesome, awesome. Yeah. Yep. Do you have anything else for me? I think that we can do more coding. Yeah, but I would suggest you to do more practice first before you know like solving the problem but all the best for your search. I hope you will land in a better place. Stealthy Hawk: Thank you so much. Have a wonderful day. It was nice meeting you. Supreme Kraken: You too. Thank you. Bye bye.
Want to get some practice yourself?
Become awesome at interviewing, and get actionable feedback from engineers at top companies – it’s 100% anonymous!