Pregunta de entrevista de Snap Finance

OOP, Spring Boot, Java, etc. Live coding: /** * * The provided code is designed to search for a target element in a rotated sorted array. * A rotated sorted array is an array that was initially sorted but then "rotated" at some pivot point, * such that part of the array is still sorted, but the sorted sequence is split. For example, the array [4,5,6,7,0,1,2] * is a rotated version of [0,1,2,4,5,6,7]. * The algorithm first finds the minimum element in the array, which indicates the point where the array was rotated. * Code has some bugs , can you debug it? * */

Respuesta de la entrevista

Anónimo

10 de jul de 2025

My answer in Python def find_rotation_point(arr): low = 0 high = len(arr) - 1 while low arr[high]: low = mid + 1 else: high = mid # The min is at mid or to the left of mid # At this point, low == high, which is the index of the smallest value return low, arr[low] # Example usage arr = [4, 5, 6, 7, 0, 1, 2] index, value = find_rotation_point(arr) print(f"Rotation point is at index {index} with value {value}")