Mary Rani

Greenhorn
+ Follow
since Aug 01, 2018
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mary Rani

No, I haven't .

Is there a noticeable difference when using StringBuffer vs StringBuilder as key? I see both have the compareTo() method supported.
1 week ago
I didn't realize that we can use StringBuffer as a Key in TreeMap, until I was asked in an interview. As a developer, I have used String.

So in this scenario, I understand that Comparable or Comparator needs to be implemented [ as Piet has mentioned ]. Thanks for clarifying this.

I am looking for an example that does this. Can someone provide a sample code?
1 week ago
Can we make StringBuffer as key in TreeMap? If yes, then what are the challenges seen while doing so? Can a sample code be provided showing StringBuffer added as key for a TreeMap?
1 week ago
Thank you. This approach works better and could get the unique list in lesser time.

Can you please suggest some links/documentation which can clearly explain what kind of data structure/collection we can choose based on the operation to be performed [ search, sort, count, add, delete ], data size, less execution time and efficient memory management ?
This would help clear some concepts for me.
2 months ago
Problem statement: Given a list/array of integers, count the number of occurrences of each element and print only those elements which occur once.

For the above problem, I have executed the following code. This works for small size lists of integers. However when the list size goes beyond 99999, the code hangs.


I understand that ArrayList works well for accessing the elements and the time complexity is less. However is it the right collection to be used, when iterating over such a large size data?
What kind of approach we need to take, to come up with an effective solution, while dealing with huge volumes of data? [ In view with deciding the right data structure/collection ]
This was also asked as an interview question a couple of times.
2 months ago
This was my initial approach. But I wanted to try with BST as well and see if I could have got a workable solution.
2 months ago
Awesome!!! I have followed your suggestion and replaced the recursive call with loop and voila. All the corner test cases have passed. I searched online, to address the exact problem i.e.

This is not uncommon with recursion, especially with unbalanced trees of significant depth.

. But could not find a proper solution. Thank you. This has cleared some concepts on BST.
2 months ago
I am sorry if the problem statement was not clear.

For any given numberOfPages, starting with pageNo:1, first node[n1] will have data as '1'. Then the next pageNo i.e. '2' will be populated in left sub-node[n2] of n1. '3' will be loaded in right sub-node[n3] of n1. '4' will be populated in the left node[n4] of n3. '5' will be loaded in the right sub-node[n5] of n3 and so on.
For example, if numberOfPages: 6, pageNo to be found: 4, then the number of pages to turn over/number of levels to traverse to 4/n4, from top-bottom would be 2. From bottom-top, would be 1. Minimum of (2,1) would be '1', which is the final output given by the code.
So for small values it works fine.
When the input values are bigger, like numberOfPages: 37455, pageNo to be found: 29835, the following exception is seen:
Exception in thread "main" java.lang.StackOverflowError
at Solution1.countBookFront(Solution1.java:91)
at Solution1.countBookFront(Solution1.java:91)
at Solution1.countBookFront(Solution1.java:91)
at Solution1.countBookFront(Solution1.java:91)

The loc giving the error is  ' countBookFront(node.right,pageNo,node.data,flag);' inside the method 'public static void countBookFront(Node node, int pageNo, int parent, boolean flag) {.....}
Hope this clarifies the confusion.
2 months ago

Mary Rani wrote:I have written a program [ Inputs: Number of pages in the book, Page number to be searched ] to store book pages [ starting from page number '1' on the right side ] in a binary tree having the following structure:
                                                                     1
                                                                    / \
                                                                   2   3
                                                                       / \
                                                                      4  5
                                                                         / \
                                                                        6  7......
The program computes the number of pages [ nodes ] to be turned, to get the suggested page number, from front[top-bottom] and back[bottom-top]. Return the minimum number of pages to be turned over, to reach the suggested page number. this works fine for small values. However it is throwing StackOverFlow Error while entering large values like NumberOfPages: 37455, PageNumberToBeFound: 29835.
What code changes can I make to avoid this error? I understand the above tree is not a balanced tree but the insertion/page order also should remain intact. Please suggest accordingly.

2 months ago
I have written a program [ Inputs: Number of pages in the book, Page number to be searched ] to store book pages [ starting from page number '1' on the right side ] in a binary tree having the following structure:
                                                                     1
                                                                    / \
                                                                   2   3
                                                                       / \
                                                                      4  5
                                                                         / \
                                                                        6  7......
The program computes the number of pages [ nodes ] to be turned, to get the suggested page number, from front[top-bottom] and back[bottom-top]. Return the minimum number of pages to be turned over, to reach the suggested page number. this works fine for small values. However it is throwing StackOverFlow Error while entering large values like NumberOfPages: 37455, PageNumberToBeFound: 29835.
What code changes can I make to avoid this error? I understand the above tree is not a balanced tree but the insertion/page order also should remain intact. Please suggest accordingly.
2 months ago
Developed a solution[GCDMatrixSoln.java] to one of the challenges given in the following site:
https://www.hackerrank.com/challenges/gcd-matrix/problem

While giving input as attached [Input.txt], the program hangs and the cursor keeps blinking in console.

Can anyone please help figure why is this happening?

while providing smaller values as input, correct output is seen. For example:
3 3 3
1 2 3
2 4 6
0 0 1 1
0 0 2 2
1 1 2 2

GCDMatrixSoln.java:


8 months ago

"but rehashing can be done in 4‑6 clock cycles.."


I understand rehashing is the process of applying the hash function to move the entries to another hashset.

What do we mean by "4-6 clock cycles"?
1 year ago
Thank you!

While inserting elements, using the contains() method, we can check for duplicate elements in list. Put() operation in hashmap, involves several operations and seems to be time consuming.

I might be missing some important aspects here. It would be helpful if the right pointers can be given to understand why hashmap is the best fit.
1 year ago
why does hashset internally use hashmap? Is it not a design overhead? what are the possible advantages of using hashmap instead of any other collection, like a list?
1 year ago