Virupaksha Swamy
BAN USERThis is Awesome!
I was thinking of using a minimum heap data structure to solve this. :/
Answer should be common not between consecutive elements but alternate elements. That is i and i+2.
- Virupaksha Swamy October 20, 2015second that
- Virupaksha Swamy October 20, 2015Dude without explanation of logic, pages of code is just garbage.
- Virupaksha Swamy October 20, 2015Also remove from HashMap the key that was found by removing after step(c)
- Virupaksha Swamy October 19, 2015Assuming each image is queried by it's path, I would use two data structures -
1. HashMap<String(path), Blob(data)>
2. DoublyLinkedList<String(path)>
Explanation:
When a request for an image path is received, check in Hashmap -
if the path already exists
(a) remove the path from Doubly linked list and put it in the beginning
(b) return blob data of the image
if the path doesn't exist in HashMap
(a) fetch the image data
(b) put <path, blob_data_of_the_image> in HashMap
(c) remove the last element from Doubly linked list
(d) insert path in the beginning of Doubly linked list
(e) return blob data
@rakhee63 Assign a prime number to every character and the hashcode will be the product of letters corresponding prime numbers.
For example:
Assign a = 2, b = 3, c = 5, d = 7 etc,.
"aa" = 2 * 2 = 4
"abc" = 2 * 3 * 5 = 30
"bac" = 3 * 2 * 5 = 30
"cab" = 5 * 2 * 3 = 30
Problem: Integer/Long overflow!
The answer is
- Virupaksha Swamy January 06, 2016Signma(i = 1 to k) (nCi * 2^i)
Time complexity O(k^2)
Space complexity O(k^2)