Skip to content

T I Double Guh ER

Raymond Chen edited this page Aug 1, 2024 · 5 revisions

TIP102 Unit 1 Session 1 Standard (Click for link to problem statements)

Problem Highlights

  • 💡 Difficulty: Easy
  • Time to complete: 5 mins
  • 🛠️ Topics: Strings, Loops

1: U-nderstand

Understand what the interviewer is asking for by using test cases and questions about the problem.

  • Established a set (2-3) of test cases to verify their own solution later.
  • Established a set (1-2) of edge cases to verify their solution handles complexities.
  • Have fully understood the problem and have no clarifying questions.
  • Have you verified any Time/Space Constraints for this problem?
  • The function tiggerfy() should take a string s and return a new string with the letters t, i, g, e, and r removed.
HAPPY CASE
Input: "suspicerous"
Expected Output: "suspcous"

EDGE CASE
Input: "Trigger"
Expected Output: ""

Input: "Hunny"
Expected Output: "Hunny"

2: M-atch

Match what this problem looks like to known categories of problems, e.g. Linked List or Dynamic Programming, and strategies or patterns in those categories.

This problem falls under: String manipulation.

3: P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea: Define a function that iterates through the string and builds a new string excluding the specified characters.

1. Define the function `tiggerfy(s)`.
2. Define the characters to remove as a string `remove_chars = "tiger"`.
3. Initialize an empty string `result` to store the modified string.
4. Iterate through each character in the input string `s`.
5. For each character, check if it (in lowercase) is not in `remove_chars`.
6. If it is not, add the character to `result`.
7. Return the `result` string.

⚠️ Common Mistakes

  • Not handling the case sensitivity of the characters.
  • Not correctly iterating through all characters of the input string.

4: I-mplement

Implement the code to solve the algorithm.

def tiggerfy(s):
    # Define the characters to remove
    remove_chars = "tiger"
    
    # Initialize an empty string to store the result
    result = ""
    
    # Iterate through each character in the input string
    for char in s:
        # If the character (in lowercase) is not in remove_chars, add it to the result
        if char.lower() not in remove_chars:
            result += char
    
    # Return the new string
    return result

5: R-eview

Review the code by running specific example(s) and recording values (watchlist) of your code's variables along the way.

Call the function with the provided examples:

print(tiggerfy("suspicerous"))  # Expected Output: "suspcous"
print(tiggerfy("Trigger"))      # Expected Output: ""
print(tiggerfy("Hunny"))        # Expected Output: "Hunny"

Expected outputs:

suspcous
<empty string>
Hunny

6: E-valuate

Evaluate the performance of your algorithm and state any strong/weak or future potential work.

  • Time Complexity: O(n) where n is the length of the input string s since we need to check each character.
  • Space Complexity: O(n) for storing the result string.
Clone this wiki locally