Pergunta de entrevista da empresa SAP

Write a function to find the first non-repeating character in a string. How would you implement a queue using two stacks? Design a URL shortener like Bitly. Explain how you would store URLs, handle collisions, and scale the system. Here’s a piece of code. It doesn’t compile/run as expected. Can you identify and fix the issue? Can you describe a challenging project you worked on, how you approached it, and the outcome? Explain the difference between depth-first search (DFS) and breadth-first search (BFS). When would you use each? What are the differences between let, const, and var in JavaScript?

Resposta da entrevista

Sigiloso

13 de jan. de 2025

Find the first non-repeating character in a string: Use a hash map to count character frequencies. Traverse the string again to find the first character with a count of 1. Implement a queue using two stacks: Use one stack for enqueuing and another for dequeuing. On dequeue, transfer elements from the first stack to the second to reverse the order. Design a URL shortener: Use a hash function to generate a unique short key. Store the mapping in a database with the short key and original URL. Handle collisions using techniques like rehashing. Fix code that doesn’t compile/run: Carefully read the error message. Check for syntax issues, missing variables, or incorrect function calls. Debug systematically. Describe a challenging project: Use the STAR method: Situation, Task, Action, Result. Focus on your role, the problem, your solution, and the positive outcome. DFS vs. BFS: DFS explores as far as possible along each branch (stack or recursion). BFS explores all neighbors first (queue). Use DFS for deep searches (e.g., finding connected components) and BFS for shortest paths in unweighted graphs. Differences between let, const, and var: var: Function-scoped, hoisted. let: Block-scoped, no hoisting issues. const: Block-scoped, value cannot be reassigned.