|
|
Good luck.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
|
Good luck with the interview.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
|
So I took one of their tests as part of a job interview. I really despise these automated assessment tests.
One of the questions involved finding the max length of a subarray of contiguous elements whose sum of the subelements is <= n.
Their example: given an array [1, 2, 3], the sub arrays are:
[1], [2], [1, 2], [2, 3], [1, 2, 3]
I didn't spot the flaw in their example until I coded up the algorithm that gave me the subarrays:
[1], [2], [3], [1, 2], [2, 3], [1, 2, 3]
Hmm, their example was missing [3]!
Stupid tests.
Marc
|
|
|
|
|
So don't keep us in suspense, how quickly did you find the solution?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I don't know, about 10 minutes. And yes, I included the comments in my "solution:"
static int maxLength(int[] a, int k)
{
List<int[]> subArrays = GetSubArrays(a);
int max = 0;
for (int n = 0; n < subArrays.Count; n++)
{
if (subArrays[n].Sum() <= k)
{
if (subArrays[n].Length > max)
{
max = subArrays[n].Length;
}
}
}
return max;
}
static List<int[]> GetSubArrays(int[] a)
{
int l = 0;
List<int[]> subarrays = new List<int[]>();
while (l < a.Length)
{
int idx = 0;
while (idx + l < a.Length)
{
int[] sub = new int[l+1];
for (int i = 0; i <= l; i++)
{
sub[i] = a[idx + i];
}
++idx;
subarrays.Add(sub);
}
++l;
}
return subarrays;
}
Marc
|
|
|
|
|
Recently I did a similar coding challenge for one of the company and I was rejected because I used too many If else statement according to them. Test was asking solution for such a trivial things you don't even bother about such things. One of the solution I provided was to find most common ints from array of ints. I guess I could have put first if else together.
public int[] GetMostCommonInts(int[] input)
{
if (input == null)
{
return input;
}
else if (input.Length == 0)
{
return input;
}
else
{
var groups = input.GroupBy(x => x);
Dictionary<int, int> dictInputCount = groups.ToDictionary(res => res.Key, res => res.Count());
int[] resultInts = dictInputCount.Where(x => x.Value == dictInputCount.Max(y => y.Value))
.Select(x => x.Key)
.OrderBy(x => x)
.ToArray();
return resultInts;
}
Zen and the art of software maintenance : rm -rf *
Maths is like love : a simple idea but it can get complicated.
|
|
|
|
|
|
Coffee is Go! The thermos contains enough for 8, yup 8, shots so I should be good for the treacherous trip to work each day.
veni bibi saltavi
|
|
|
|
|
You got yourself a job already?
I'm impressed - perhaps you'd better explain the process to Glenn?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
So they didn't come back after cancelling the interview then?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
No according to the agent they hired some else...never mind! Next interview Monday...
|
|
|
|
|
Good luck!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
It's a small start up that I've been working with on and off for nearly a year. The job is being turned full time.
veni bibi saltavi
|
|
|
|
|
Herself came home last night, with a new toy - an old wooden board, covered in letters and numbers, with a small glass that we were to put our finger on.
I was reluctant, but ... you gotta keep the other half happy, and sometimes that means doing things you don't really want to.
So we sat down, and put our fingers on the glass.
It moved!
And at the same time, the air was filled with a weird discordant noise - I couldn't tell from where; it seemed to come from the very air around us!
The glass continued to move and I could see it was spelling out letters:
An 'A', then an 'L', an 'I', a 'V' and finally an 'E'
I snatched my finger away! "It's telling us it's ALIVE?" I yelled in horror. The sound stopped, and I relaxed a little.
She gave me That Look.
Sheepishly, I returned my finger to the glass. The sound resumed, and the glass started moving again: A...H...H...A...H...A...H...A
I jerked away again: "It's laughing at us!"
Again, The Look, promising me nights on the couch if I didn't continue ... reluctantly I returned to the glass.
S...T...A...Y...I...N...A...L...I...V...E
I grabbed the glass and threw it across the room as the horrible truth dawned upon me: I realized exactly what Herself had done.
How could she bring such evil into our home?
The horror, the horror. A Bee Gee Board...
My coat is just over there - could you pass it to me?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: Sheepishly Oops, Freudian (or maybe ovine) slip there.
|
|
|
|
|
Bah! Too much lead up!
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Too freakin funny or would that be Barry funny?
New version: WinHeist Version 2.2.2 Beta I told my psychiatrist that I was hearing voices in my head. He said you don't have a psychiatrist!
|
|
|
|
|
Quit Robin his line.
/ravi
|
|
|
|
|
keeping the missus happy, how deep is your love?
(They got a song called "Cucumber Castle" - extra points for anyone that can get that into natural conversation.)
Sin tack ear lol
Pressing the any key may be continuate
|
|
|
|
|
please, please slap yourself! that was so bad it was good.
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|