Uber Interview Question

Add code to run and complete the task

Interview Answer

Anonymous

Oct 13, 2017

package com.test; class RateLimiter { public static void actuallyCallAPI() { // Should not be called more often than 10 times per second. // This function should not be changed. System.out.println("Called API."); } public static void callAPI() { // TODO: Add your implementation here. actuallyCallAPI(); // If we drop the call, let's just display: System.out.println("Did not call API."); } public static void testRateLimiter() { for (int i = 0; i < 12; i++) { callAPI(); } System.out.println("Waiting..."); try { Thread.sleep(1000); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } for (int i = 0; i < 2; i++) { callAPI(); } } public static void main(String[] args) { testRateLimiter(); } }