Saurabh Pillai

Ranch Hand
+ Follow
since Sep 12, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Saurabh Pillai

Liutauras Vilda wrote:You have comment:
That comment is incorrect. There is a key and a value, not the two keys.

You have some magic number there, which is 25. You either supposed to have a descriptive variable what it represents, or explanation why is 25 there. For example: restricted length on db table's field.



I add 2 keys because, isValid will have either {"true", "false"} and if validation failed then message will have appropriate error message.
7 years ago

Liutauras Vilda wrote:Now I'm playing silly, you might want to save it to database or something? Then change the method name if that's the case.


I named the method according to CRUD. This is part of REST webservice. User object contains what actual user entered during signup process. I need to validate that input and then save the user into database. I kept the return type as void because, why do I need to return the user object?
7 years ago

Liutauras Vilda wrote:

Saurabh Pillai wrote:


This signature doesn't make sense to me. Think why.



Just want to say that this is not copied from production. About the problem with signature, I forgot to add throws clause. Is that it?
7 years ago

Campbell Ritchie wrote:Or, in non‑cowboy language, start throwing some Exceptions and get it over and done with. Who needs to do lots of processing when one already knows the result is going to be invalid?


I am validating all the fields so that I can inform user about all the problems with any of the fields in single error message, hoping user would correct it in one go. Apart from that, do you think having validation and save into separate methods is good practice?
7 years ago
Let's say I want to save User object. Before I save it, I have to validate it through various business validations. How do I go about it?

In my current code, I see it coded 2 ways as below.



I am curious about how do you folks code this. ty
7 years ago
Problem Statement: Design and implement a data structure that can store all the different numbers from two separated streams. Implement two methods 1) intersection() 2) union()

Below is my take,


Time Complexity intersection method:

Let's say Set has N elements.
- for loop, O(N)
- contains and add method, O(1)

O(N) +  O(1) = O(N)


Time Complexity union method:

Let's say Set1 has N elements and Set2 has M elements.

- Set<Integer> union = new HashSet<Integer>(s1);   O(N)
- union.addAll(s2); O(M)

O(N) + O(M) = O(N + M)  Is this correct?

7 years ago
Hi Campbell,

If you look at the commented code, I have tried to pass 3 different size arrays (edge cases) to test if it fails. Irrespective of size of the array and order of elements, my proposed solution will first sort the array and retrieve last 3 elements.
You are suggesting that you have a solution which will run in linear complexity. Is it one of the sorting algorithms and instead of sorting whole array, you only care about sorting until you get 3 max numbers?
7 years ago

Carey Brown wrote:I wouldn't use a sort(). A HashMap with count for a value would be quicker.



This is how I have implemented it.



Time Complexity: about O(N)
7 years ago

Saurabh Pillai wrote:
Time complexity of getDuplicates method:

Let's assume that list has N elements.

- Collections.sort(input), O(N LogN)
- duplicates.add(a);, for HashSet add is constant O(1)

O(N LogN) + O(1)
= O(N LogN)



Sorry I miscalculated this. It should be,

- Collections.sort(input), O(N LogN)
- for loop, O(N)
-- duplicates.add(a);, for HashSet add is constant O(1)

O(N LogN) + O(N) + O(1)
= O(N(LogN + 1))
= O(N LogN)
7 years ago
Problem statement (AS IS): Write a program to find out the duplicates in the given list of objects. Explain the time complexity of your solution (Big O Notation)



Time complexity of getDuplicates method:

Let's assume that list has N elements.

- Collections.sort(input), O(N LogN)
- duplicates.add(a);, for HashSet add is constant O(1)

O(N LogN) + O(1)
= O(N LogN)>
7 years ago
Hi everyone,

I came across below problem and here's my take on it. Can we discuss the solution?

Problem statement (AS IS): Write a java program to find out the first three highest numbers of the integer array in descending order. Explain the time complexity of your solution (Big O Notation)



Time Complexity of getArray method:

No. of elements in the array is N and no. of elements to be returned is K.

- Assume that (Arrays.sort(a);) uses Merge/quick sort, O(N logN)
- for loop, O(K)
- result[j] = a[i];
-- a[i],access of array is constant,  O(1)
-- result[j], insertion in array, O(K)

O(N logN) + O(K) + O(1) + O(K)
= O(N logN + 2K)
= O(N logN + K) (Drop the constant)
= O(N logN) (for very small values of K)

Does this sound right? Thank you
7 years ago
Here's the code https://jsfiddle.net/gr55jpaq/1/

I want to add onClick function to each <a> tag of div that has 'moviePosterDiv' class. I am new to jQuery.
I am learning Spring WebSocket. I have successfully run this Spring WebSocket tutorial. Now I am trying to incorporate it as-is in my existing Spring MVC application. When I run it from Chrome browser, I see below error in its dev console.

Chrome Console

Server Side Error


Client Side


Server Side



I have tried to solve this for couple hours now. How do I resolve this?

ty

CrossPost: https://stackoverflow.com/questions/44609914/sockjs-fails-to-create-connect-to-spring-websocket
7 years ago
Hi everyone,

I submitted the attached solution for given design problem to prospective employer. I did not hear back from them :-(. This doubts me about my solution hence want to have a second opinion. As far as the solution goes, it works. Tested with different scenarios. They mentioned that they want "production quality" solution.

Github :- https://github.com/saurabh-pillai/Theater-Seating

Any input is appreciated.Thanks.

PS:- I had to upload source code to Github because I could not upload zip/txt files as an attachment.
8 years ago