Skip to content

Instantly share code, notes, and snippets.

@arturogutierrez
Created February 25, 2021 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturogutierrez/4381499b61a9b3d7da9a2d579a7dcba2 to your computer and use it in GitHub Desktop.
Save arturogutierrez/4381499b61a9b3d7da9a2d579a7dcba2 to your computer and use it in GitHub Desktop.
Problemas de entrevistas técnicos
/**
* 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