Ben Synes

Ranch Hand
+ Follow
since Jul 18, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
37
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ben Synes

I actually did the codility lesson on odd occurrences and had a similar answer to Campbell Ritchie and scored 100%. From what I remember, all elements in the array were > 0. Although the question from what I remember guaranteed the array would have an odd number of elements.
3 years ago

Carey Brown wrote: Try exercise sites like https://projecteuler.net/



I like this, and the fact it gives an overview of a more efficient way of solving the task once you have completed it is really useful, thanks!
3 years ago
Hi Guys,

Hope you are all well.

Recently, I have been looking for a new job, I have been working as a Java/Golang engineer for about 2-3 years now.

Lately, the obstacle course of getting through interviews, coding tests, pair programming coding tests, I have begun to notice more emphasis on mathematical based coding solutions. Now I am not too bad at some of these, but I am not a natural mathematician I feel.

My questions are, apart from practicing these coding exercises among the myriad of offerings to strengthen my skills:
1. Are there books/sources you would recommend to help with algorithm based puzzles?
2. When I'm totally stuck and really cannot find a 100% performance based solution, what would you suggest, investigate solutions posted online and try to learn/emulate them?
3. Any other advice you can throw out there, greatly appreicated.

Thank you.

3 years ago
Thanks Piet Souris,

At least I have learned the difference between a substring and a subsequence. And I really do agree, this seems far too difficult for a question, particularly of someone of my level anyway. This stack overflow also helped https://stackoverflow.com/questions/15505508/what-is-the-difference-between-string-substring-and-string-subsequence (although I hope the moderators of the ranch do not mind me posting this here)

And now having understood it, I assume the original question was the longest subsequence that is in String1 and not in String2, which would in fact give "abbbb". In fact, "abbbb" is also the shortest subsequence too, so maybe I was right in recalling the shortest - but the question definitely stated substring, maybe they meant subsequence.
3 years ago
Sorry Dave Tolls,

It was a session based test so I can't redirect you to see it at first hand. Yes maybe I am paraphrasing incorrectly, but it definitely did mention the shortest substring. Maybe the context was incorrect within the question itself. Theres some smart guys who've probably read this post and the examples of the questions are definitely what was shown in the question, but if these smart guys cannot make head nor tail of it, then I can only assume the question was badly constructed, or perhaps even plainly wrong.
3 years ago
Sorry Dave Tolls,

It was a session based test so I can't redirect you to see it at first hand. Yes maybe I am paraphrasing incorrectly, but it definitely did mention the shortest substring. Maybe the context was incorrect within the question itself. Theres some smart guys who've probably read this post and the examples of the questions are definitely what was shown in the question, but if these smart guys cannot make head nor tail of it, then I can only assume the question was badly constructed, or perhaps even plainly wrong.
3 years ago
Hi Piet Souris

Potentially it could be that, do you see how they can determine the "abbbb" answer from your query?
3 years ago
Hi Campbell Ritchie

Yes, it is totally confusing. I can't find anything on google relevant for this question either.

The question went along these lines...

"A son was bored, so the mother gave him two strings to play with, he had to determine the shortest possible substring difference that is in String1 but not in String2"

There was an example, something along the lines of:

String s1 = "ababa"
String s2 = "aabaa"

And the answer to this one was 3, "bab"

Clearly I can distinguish that "bab" is different from the same characters in s2.

But with the:

String s1 = "abababab";
String s2 = "babababa";

And 5, "abbbb" I cannot see nor determine what conditions give this result???

3 years ago
Hi,

I just completed an online exam for Java, and I was asked to list the substring differences that are in String1 and not in String2.
The examples were:
 


And the answer should be 5, abbbb.

Can someone please explain how this is so? I assumed as each character is different, the answer could be 8, but that option was not available on the multiple choice answers.
3 years ago
Thank you for help. I really appreciate it.

7 years ago
I googled about "first principles" before attempting the task. Surprisingly there are terms around math such as:

starts with formal logic, the axiomatization of arithmetic, lambda calculus (the theory of partial recursive functions), and automata theory up through Turing machines.



All looks a bit heavy, of course I learned Big O notation at university, and yes Im even further noviced now, because it was Computer Science. To late for a refund I guess, but perhaps their failings should be something I correct by myself.

7 years ago

Junilu Lacar wrote:I don't know if I would have equated the "no throw guarantee" to the use of a try-catch either. There are only a few things that can cause an exception so I would have just put up some guard clauses. Try-catch blocks are expensive and if performance is a primary concern, you should try to avoid using them.



So what kind of guard clauses could I use here? What kind of cases could be guarded against?

I saw initially only a concern of IndexOutOfBounds, but this was mitigated with the enhanced for. As there are many Runtime exceptions which could potentially be thrown, a guard against all of them would be kind of lengthy no?


7 years ago
Thanks for the answer. Coincidentally when I was reading about the performance of the enhanced for  vs plain for, there were a third set of results for the binary search, which were faster than both of some of the datasets. When I saw this problem, I just saw String, which I thought was simple enough to detect in a standard for way, as you rightly pointed out, the "hidden" clue is the sorted. Thanks for pointing this out. I feel such a novice now.
7 years ago

Henry Wong wrote:I think that you forgot about the "sorted" part of the question. There is a very good reason that the inputs are guaranteed to be sorted.

Henry



I dont understand? Guaranteed to be sorted would be perhaps meaning a Comparator was used? But if so, we still need only return the index if found in the array, regardless of position??

Please explain to me if you could.

7 years ago
I remember reading on JavaCodeGeeks an in depth analysis of the for vs the enhanced for, and the results indicated that the enhanced for was generally quicker overall. But maybe this was with only certain data types.

I got no feedback whatsoever as to what was wrong with my solution.
7 years ago