LRU Cache LeetCode Solution

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.
get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
The cache is initialized with a positive capacity.
Follow up:
Could you do both operations in O(1) time complexity?
Example:
LRUCache cache = new LRUCache( 2 /* capacity */ );

cache.put(1, 1);
cache.put(2, 2);
cache.get(1);       // returns 1
cache.put(3, 3);    // evicts key 2
cache.get(2);       // returns -1 (not found)
cache.put(4, 4);    // evicts key 1
cache.get(1);       // returns -1 (not found)
cache.get(3);       // returns 3
cache.get(4);       // returns 
Solution : 
class LRUCache extends LinkedHashMap<Integer,Integer>{
private int capacity;
    public LRUCache(int capacity) {
        super(capacity,0.75F,true);
        this.capacity = capacity;
    }
    
    public int get(int key) {
        return super.getOrDefault(key,-1);
    }
    
    public void put(int key, int value) {
        super.put(key,value);
    }
    
    @Override
    protected boolean removeEldestEntry(Map.Entry<Integer,Integer> eldest){
        return size() > capacity;
    }
}

/**
 * Your LRUCache object will be instantiated and called as such:
 * LRUCache obj = new LRUCache(capacity);
 * int param_1 = obj.get(key);
 * obj.put(key,value);
 */

Amazon List of LeetCode Questions

1. Two Sum

Two Sum Solution

2. LRU Cache

LRU Cache Solution

3. Number Of Islands

4.Longest Palindromic Substring

5. Lowest Common Ancestor of a Binary Tree

6. Add Two Numbers

7.Word Ladder

8. Reverse Linked List

9. Serialize and Deserialize Binary Tree

10. Valid Parentheses

11. Letter Combinations Of a Phone Number

12. Copy List With Random Pointer

13. Longest Substring With Out Repeating Characters

14. Trapping Rain Water

15. Min Stack

16. Lowest Common Ancestor Of a Binary Search Tree

17. Rotate Image

18. Best Time To Buy And Sell Stock

19. Validate Binary Search Tree

20. Word Break

21. Linked List Cycle

22. Group Anagrams

23. 3Sum

24. Product Of Array Except Self

25. Valid Anagram

26. Sliding Window Maximum

27. Search A 2D Matrix

28. Merge Two Sorted Lists

29. Merge K Sorted Lists

30. Word Ladder II

31. Kth Largest Element In An Array

32. Palindrome Linked List

33. Intersection Of Two Linked Lists

34. Subsets

35. String To Integer

36. First Unique Character In a String

37. Binary Tree Level Order Traversal

38. Count Primes

39. Gray Code

40. Two Sum Input Array Is Sorted

41. Insert Delete Get In Random O(1)

42. Binary Tree Right Side View

43. Design Twitter

44. Reverse Words In A String II

45. Rotate Function

















SDLC

SDLC : Software Development Life Cycle

SDLC is the process that provides software with the highest quality and lowest cost in the shortest time.

Steps involved in SDLC :

1. Identify the requirements.

2. Planning

3. Design

4 . Build

5. Test

6.Deploy

7. Maintain

Different SDLC Models we have :


1. Waterfall Model

2. Agile Model

3. Iterative Model

4. V-Shaped Model

5.Big Bang Model

6.Spiral Model



Top Sites To Review Resume For Free



1. Zety Resume Builder : https://zety.com/ 2. Resumonk : https://www.resumonk.com/ 3. Resum : https://www.resume.com/ 4. VisualCV : https://www.visualcv.com/ 5. Cvmaker : https://cvmkr.com/ 6. ResumeUP : https://resumup.com/ 7. Resume Genius : https://resumegenius.com/ 8. Resumebuilder : https://www.resume.com/builder 9. Enhancv : https://enhancv.com/




--------------------------------------------------------------------------------------------------------------------------

Linux Command Line - Basic Commands


What is the Command Line ?

Command line allows direct access to the computer .

Easier than :

-> GUI (Graphical User Interface)

->  Good way and better way in accessing files , programming and helpful in deploying or coding environments.

Command line is also called are as follows :

 -> CLI (Command Line Interface).

-> Terminal

-> Bash Shell / Shell

-> Command Prompt / cmd (Windows)

What is the Use of Command Line  ?

-> Extremely useful in Programming . (Eg : Ruby or Rails)

-> Get Things done easier and quicker.

-> Great skill.


Opening the Command Line :

Ctrl + Alt T

Copy and Paste Command Line :

Ctrl + C and Ctrl V doesn't work in terminal

Ctrl + Shift + C for Copy and Ctrl + Shift + V for Paste in Terminal.

Calendar command to view all the facts happened on each day.

pwd command is know as print working directory which is used to print the working directory.

Changing Directories in the Command Line

cd old directory new directory

ls command -> to list all the folders in the present directory.

ls -t -> to list folders that are recently changed.

ls --size -> to list folders and the size of the files.

ls -l -> to list out all the bunch.

ls -t -r -> To flip the order .

ls -a ->  To list all hidden folders.











Featured Post

H1B Visa Stamping at US Consulate

  H1B Visa Stamping at US Consulate If you are outside of the US, you need to apply for US Visa at a US Consulate or a US Embassy and get H1...