Created
February 25, 2021 11:59
-
-
Save arturogutierrez/4381499b61a9b3d7da9a2d579a7dcba2 to your computer and use it in GitHub Desktop.
Problemas de entrevistas técnicos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Given an sorted array of integers you must to find the unique integer | |
* number that is not duplicated. Return -1 otherwise. | |
* Note: Each number only can occur up to 2 times | |
* | |
* Example 1: | |
* Input: [0, 0, 1, 2, 2] | |
* Output: 1 | |
*/ | |
class SingleNumber { | |
} | |
/** | |
* Design a data structure that follows the constraints of a | |
* Least Recently Used (LRU) cache. | |
* | |
* Implement the LRUCache class: | |
* - LRUCache(int capacity) Initialize the LRU cache with positive size capacity. | |
* - int get(int key) Return the value of the key if the key exists, otherwise return -1. | |
* - void put(int key, int value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. | |
* If the number of keys exceeds the capacity from this operation, evict the least recently used key. | |
* | |
* Could you do get and put in O(1) time complexity? | |
* | |
* Example 1: | |
* LRUCache lRUCache = new LRUCache(2); | |
* lRUCache.put(1, 1); // cache is {1=1} | |
* lRUCache.put(2, 2); // cache is {1=1, 2=2} | |
* lRUCache.get(1); // return 1 | |
* lRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3} | |
* lRUCache.get(2); // returns -1 (not found) | |
* lRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3} | |
* lRUCache.get(1); // return -1 (not found) | |
* lRUCache.get(3); // return 3 | |
* lRUCache.get(4); // return 4 | |
*/ | |
class LRUCache { | |
} | |
/** | |
* Find the first common ancestor of two nodes in a binary tree. | |
* NOTE: This is not necessarily a binary search tree. | |
* | |
*/ | |
class FirstCommonAncestor { | |
} | |
/** | |
* Detect if there is a cycle in a linked list | |
* | |
*/ | |
class DetectCycle { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment