OfferGenie
All Questions

Basic String Manipulation

AdobeTechnicalDifficulty: N/A
Share on

Ready to answer it out loud?

Run a mock interview on this exact question and get instant AI feedback.

Practice this question

Question Explain

Write a function to reverse a string without using built-in reverse methods.

Example: Input: "hello" Output: "olleh"

Requirements:

  • Handle empty strings
  • Consider Unicode characters
  • Optimize for space complexity

Answer Example

String Reversal Solution:

  1. Approach:

    • Two-pointer technique
    • In-place character swapping
    • Handle edge cases
  2. Implementation:

function reverseString(str: string): string {
  const chars = [...str]; // Handle Unicode properly
  let left = 0;
  let right = chars.length - 1;
  
  while (left < right) {
    // Swap characters
    [chars[left], chars[right]] = [chars[right], chars[left]];
    left++;
    right--;
  }
  
  return chars.join('');
}

// Test cases
console.log(reverseString("hello"));     // "olleh"
console.log(reverseString(""));          // ""
console.log(reverseString("🌟✨"));      // "✨🌟"
  1. Complexity Analysis:

    • Time: O(n)
    • Space: O(n) due to string immutability
  2. Edge Cases:

    • Empty string
    • Single character
    • Unicode characters
    • Special characters
  3. Testing:

    • Unit tests
    • Performance tests
    • Unicode handling
    • Memory usage

Company Context (Adobe):

  • Clean code practices
  • Performance optimization
  • International support
  • User experience focus