This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.

tangara goh

Ranch Hand
+ Follow
since Dec 27, 2009
Merit badge: grant badges
Biography
I am a beginner in Java and hope to pick up the trade secrets so that I can move on to Android development
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
221
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by tangara goh

I refer to https://dev.java/learn/lambdas/first-lambdas/ specifically



How do you apply final to the totalPrice ?
3 months ago
Hi guys,

I'd like to seek advice if I should go for a Kubernetes CKA certification, since I feel that there seems impossible for me to really get into a good company that will accept me, without passing a online coding test, that can comes out any questions, same applies to non-coding interviews, where the questions can come from anywhere - it could be a OOP question, a DB question, a front-end person to even if you don't know what csv stands for, even though we all know what csv is, the interviewer will deem you don't know if you can't recall what it stands for at the interview moment.

So, I am hoping to work around the situation, given my age etc and my learning of DSA LC style seems will take years before or never will beat the system.

Does a Kubernetes CKA certification allows one work remotely, and internationally anywhere in the world ?

I am not sure if it is, cos I do not want to jump into it to discover black holes like Leet Code testing ....

Hope someone who knows about Kubernetes will share with me more, should I take up or not ?

Will it take so much time that I won't have time to learn the rest of the DSA stuff I haven't covered plus practice ?
4 months ago

Carey Brown wrote:Is 'name' in Transaction the same as Customer.name, e.g. "Joe Smith"? If so then Transaction.name is redundant because you already have Transaction.custid that can be used to retrieve the name.

Transaction is not a sub-class of anything so you can't call 'super()' as you've done on line 26.

In the Customer constructor you pass in a List of Transactions which is inappropriate. Id, name, and citizenshpNo are fixed attributes of a Customer but Transactions are different in that (supposedly) you can add them over time with a properly named method.



I think name should be Transaction Name, as the name was given as one of the fields to me to work on this assignment.

Should I add List<Customer>customers to Transaction class then ?  sorry but really i think my basic is rather shaky.

so a list of Customers can retrieve the Transactions but in a list of Transaction, we can also see who are the customers..so what make of that ? How do I make this assignment as simpler as it can be, since it is like an open-ended thing, again....
5 months ago
Hi guys,

I need help to come up with some APIs which I have again no clue how to go about doing it.

Here's the fields given to me :


Customer  

      id
       name
       citizenshipNo

Trans
      id
       custid
       name
       amount



Here's what i came up for the POJO but really I am not sure if i can just make it a one-to-many relationship to make my things easier for me to complete my task.


I am not sure how the CRUD api should turn out in terms of the Transaction that should appear ?

So, there is no balance amount given, should I just take the amount in Transaction and give it to Customer when I create the Customer starting with 0 amount and there is no deposit, and since there is no function like withdrawal so how can I do things properly based on the above, as was given to me?


5 months ago

Piet Souris wrote:hi Tangara,

I would not use that method at all. In the case of a triple product, I would split the array in two parts, the negative numbers and the rest, sort the two subarrays, and then the max product is either the product of the two smallest negative numbers and the largest non-negative number, or the product of the three largest non-negative numbers. This can be generalized to the max product of K elements



Hi Piet,

I am not sure if I follow you cos I did it using this way, sort it in descending order so am not sure if it meets the split the array into 2 parts as you have suggested.



I must admit this is done with assistance from chatGPT because initially I have difficulty it to do the reverse Collection and then found out it can only work if it is a List<Integer>

but the above solution only got 33% passed and I am not sure where it goes wrong with it.
https://i.imgur.com/q90cZDS.png
5 months ago
I attempted this question from Codility and naturally I have to see the solution to know how to do it.




A non-empty array A consisting of N integers is given. The product of triplet (P, Q, R) equates to A[P] * A[Q] * A[R] (0 ≤ P < Q < R < N).

For example, array A such that:
 A[0] = -3
 A[1] = 1
 A[2] = 2
 A[3] = -2
 A[4] = 5
 A[5] = 6

contains the following example triplets:

       (0, 1, 2), product is −3 * 1 * 2 = −6
       (1, 2, 4), product is 1 * 2 * 5 = 10
       (2, 4, 5), product is 2 * 5 * 6 = 60

Your goal is to find the maximal product of any triplet.

Write a function:

   class Solution { public int solution(int[] A); }

that, given a non-empty array A, returns the value of the maximal product of any triplet.

For example, given array A such that:
 A[0] = -3
 A[1] = 1
 A[2] = 2
 A[3] = -2
 A[4] = 5
 A[5] = 6

the function should return 60, as the product of triplet (2, 4, 5) is maximal.

Write an efficient algorithm for the following assumptions:

       N is an integer within the range [3..100,000];
       each element of array A is an integer within the range [−1,000..1,000].



My question is if it is not just triplet but the multiplication of Nth number do we still use this method ?



6 months ago

Stephan van Hulst wrote:No. The problem is that arraySum may overflow when you're adding a to it. So that variable needs to be a long. When you cast totalSum, it's already too late.

Here is how I would implement Piet's solution:



I am not sure where I went wrong after trying to modified my answer to below :



cos your solution can't be used in Java 8.

So, this is also another problem I have to deal with, what version should I train myself in ?  Hope to hear expert advice.  Another thing is that different companies use different platforms.  So, locally, they like to use HackerRank but overseas companies like to use Codility.

I feel so exhausted from studying all these kind of tests...and I am not progressing fast enough cos I will sometimes studying concepts like Thread, Java 8 Streams and even revising generic etc so all my time is fully used up plus I also need to do housework etc.  Really hope to have some advice.  Tks
6 months ago

Carey Brown wrote:Sorry, guess there isn't any code.  Just the problem statement.

A[0] = 3
A[1] = 1
A[2] = 2
A[3] = 4
A[4] = 3

We can split this tape in four places:

      P = 1, difference = |3 − 10| = 7
      P = 2, difference = |4 − 9| = 5
      P = 3, difference = |6 − 7| = 1
      P = 4, difference = |10 − 3| = 7

If you divide the array into sumOfLeft and sumOfRight
Where P == 1
Left = 3
Right = 1 + 2 + 4 + 3 = 10
diff = Math.abs( left - right ) = 7



After spending the last 0.5hr studying, I still don't understand.  This is really demoralising.

I mean why when P == 1 the Left is 3 and when P == 2 then why left is 4 and not 1 ?  And as it progress to P == 3, it becomes worse, why it will skip 4 for the sum?

I am really stupid.  Can you explain to me like I am a 5 years old ?
6 months ago

Piet Souris wrote:The exercise is about splitting an array into two parts. In your example the split is after the first element. Then we determine the sum of both parts. The first part contains just 3 and the other part sums up to 10. The question is where the split must be in order that both sums are as close as possible.

Did you figure out an algorithm yet?



No.  I can't understand the question at all and most of the time I need to google to find answers...and understand from there...and my progress is so slow I have to retreat from all the interviews cos it will involve this kind of online test and I am so upset when will I be ready to sit for a test...

But, thanks let me studying what you said when i wake up 2morow.
6 months ago

Piet Souris wrote:Well I used the sum of the array, and with the elements going from 1 to 100.000, the sum is about 5 billion. So internally I would use longs, and cast the answer to int. But with your method, this is not necessary. I just mentioned my method because it is immediately clear that it is O(N).



You mean like that ?

6 months ago

Carey Brown wrote:The link in your title doesn't work for me. Would you cut and paste the code here.



But i have already copied the entire question here.
6 months ago

Piet Souris wrote:That my formula fails is due to overflow. If the array contained longs then there would be no problem. For instance, if the array is {1, 3, 4, 5}, then the missing element is 5*6/2 - 13 = 2.



May I know how to return long if the method starts with int ?
6 months ago
Hi guys,

I have been staring at this question but I am not getting anywhere....




A non-empty array A consisting of N integers is given. Array A represents numbers on a tape.

Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1].

The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])|

In other words, it is the absolute difference between the sum of the first part and the sum of the second part.

For example, consider array A such that:
 A[0] = 3
 A[1] = 1
 A[2] = 2
 A[3] = 4
 A[4] = 3

We can split this tape in four places:

       P = 1, difference = |3 − 10| = 7
       P = 2, difference = |4 − 9| = 5
       P = 3, difference = |6 − 7| = 1
       P = 4, difference = |10 − 3| = 7

Write a function:

   class Solution { public int solution(int[] A); }

that, given a non-empty array A of N integers, returns the minimal difference that can be achieved.

For example, given:
 A[0] = 3
 A[1] = 1
 A[2] = 2
 A[3] = 4
 A[4] = 3

the function should return 1, as explained above.

Write an efficient algorithm for the following assumptions:

       N is an integer within the range [2..100,000];
       each element of array A is an integer within the range [−1,000..1,000].




The part that is doing my head in is :


P = 1, difference = |3 − 10| = 7



it is stated that A[0] = 3, but the entire array doesn't add up to 10...
so where does 10 come from ?

Hope someone can explain to my dumb head.
6 months ago

Piet Souris wrote:Assuming that the creation of the set and the checking of the array-elements are both O(N), the whole operation is O(N). A bit more clear is returning (N + 1) * (N + 2) / 2 - sum of the array elements.



So the thing is I do not know why Codility platform put O(N) or O(N * log(N)) ?

Does it means either the time Complexity can be both O(N) or O(N * log(N)) ?

This one - (N + 1) * (N + 2) / 2 - sum is tried but it will not passed the large range test.
6 months ago