Amazon Interview question

40mpg

Member
Join Date
Dec 2021
Location
Oakland, CA
Posts
82
This is maybe off topic, but I just had an interview at Amazon and was asked to do this question. I was blanked in the head, was wondering if anyone here wanna give it a shot.

1. User input an angle on the HMI (e.g 90 degrees)
2. Output an alarm when the angle formed between the minute hand and the hour hand on the clock matches the desired angle (e.g 3:00 o clock would form 90 degrees between the hour hand and the minute hand...then the logic needs to output an alarm)
3. Limit user input to 0-180 degrees

I said, user system clock...uhhhh...use an integer to represent the angle....and blah blah and I failed.

They assured me this is a similar use case in production...

I was trying to do this in ladder logic...but I guess you can do it in structure text too , or anything really.
 
Last edited:
Every 90°? Or every 90° on the hour or half hour? Actually xx:32:30. But if any angle then that wouldn't matter, really.

The easiest way I can think of is to calculate what minute position the hour hand is pointed at that scan and add or subtract the number of minutes per the HMI entered angle. Then compare the minute hand to the anticipated value.


EDIT: I was getting emails (on my personal email account I never use for business) from an Amazon facility in Brownstown, Michigan wanting a programmer with my experience for 5 years until they finally gave up - or found someone dumb enough to go work for their 'algorithm' system.
 
Last edited:
Interesting, first idea for me that came to mind was that I would transfer the positions to degrees as it is 360° around then just minus the smaller from the bigger and you'll get a result.
 
EDIT: I was getting emails (on my personal email account I never use for business) from an Amazon facility in Brownstown, Michigan wanting a programmer with my experience for 5 years until they finally gave up - or found someone dumb enough to go work for their 'algorithm' system.

Can you elaborate more on the "algorithm system". What does that mean?
 
Can you elaborate more on the "algorithm system". What does that mean?


They have a system that monitors every employee and an algorithm decides when they are about to make a mistake and fires them before they make that future mistake.


Plus it monitors many other aspects of employment and reports anything it flags to be dealt with.
 
[Update: d'Oh, proportionality constants were off by an order of magnitude!]

12- or 24-hour clock ;)?

from a T0 of either noon or midnight, or of the most recent occurrence of any multiple of 720/11ths minutes after noon or midnight, solve each of the two* following linear systems for minutes
mangle = +(minutes * 6)
hangle = +(minutes * .5)
mangle = hangle + HMI_angle
minutes > 0

mangle = -(minutes * 6)
hangle = -(minutes * .5)
mangle = hangle + HMI_angle
minutes < 0
N.B. the solutions are identical except for the sign of minutes.

Then increment/decrement those two ±minutes solutions by ±720/11ths of an hour, respectively, ten times to get the other ten solutions. If HMI_angle is 0 or 180, only the + solution is needed.
 
Last edited:
They assured me this is a similar use case in production...
And you then asked exactly what case ?
I call it BS.
I would also demand to know why I had failed the test.

Unless there is something that is not mentioned, then I think it could be solved relatively easily.
Convert minutes to angle, convert hours to angle, calculate the difference. If the difference is the same as the operator has set, then trigger the alarm.

Maybe they wanted to see some kind of clever programming.
But in industrial automation, you dont want any clever or obscure programming hacks. You want the code to be simple, easy to maintain, and that it is tolerant against misuse and abnormal situations.

For this when you have made the code, you test it and try to break the functionality, and by that figure out how to make it more fool-proof.
For example, the calculation will probably not create an exact match in most situations, which means the alarm will not trigger if you have a simple (angle_between_hands = userset_angle). So to counter this the alarm must be triggered when it senses that the minute hand passes by the point where it should have triggered the alarm.

edit: I think that the testers wanted you to create a function based on trigonometric functions. By that you can condense the formula into a compact one-liner.
However, that still does not take into account the realworld scenario, that the PLC will not always see the moment that the angle values intersect. Even if the clock is internal in the PLC, it is as far as the PLC code is concerned the angles are sampled discretely and not continously.
 
Last edited:
Calculate two constants:
coshmi = cos(HMI_angle)
PI = 4 * atan(1)
Then, at any time, sample hours, minutes and seconds (via SSV, RTC, whatever):
mns = minutes + (seconds ÷ 60)
hrs = (hours modulo 12) + (mns ÷ 60)

cmns = cos(mns*PI/30) ### <= upward component of minute hand as unit vector
smns = sin(mns*PI/30) ### <= right-ward component of minute hand "
chrs = cos(hrs*PI/6) ### <= upward component of hour hand "
shrs = sin(mns*PI/6) ### <= right-ward component of hour hand "

coshm = (cmns*chrs) + (smns*shrs) ### <= dot product of minute- and hour-hands as unit vectors, = cosine of angle between them
Detect when the value of coshm crosses the value of the constant coshmi, which crossing will be when the angle between the minute and hour hands crosses the HMI_angle. It will get messy to detect a crossing when HMI_angle is near 0 or 180, will need to check for change of sign of cross product ((cmns*shrs) - (smns*chrs)).

N.B. this only works because the target angle is in the monotonic range [0:180], so the cosine of that range is also monotonic over the range [+1:-1], so it saves the wraparound checks (hour hand at ~327° deg, minute hand at ~57°) and therfore could be implemented as a one-liner.
 
Last edited:
And you then asked exactly what case ?
I call it ...

I wonder if the use of a 12-hour clock is a proxy for a similar problem e.g. two geared shafts running at different ratios, or two production lines making discrete products at different frequencies, and delivering them to the same conveyor at the same place.
 
They have a system that monitors every employee and an algorithm decides when they are about to make a mistake and fires them before they make that future mistake.


LOL, Minority Report.

The funniest bit was Tom Cruise's character chasing his old eyeballs down the hallway.
 
Hmmm... To me the easy solution is this:

IF Hours > 12 THEN hours - 12
Hour_Angle = Hours * 30
Minute_Angle = Minutes * 6
Test_Angle = Absolute(Hour_Angle - Minute_Angle)
IF Test_Angle = HMI_Angle THEN Pass ELSE Fail

This puts both hands into 360 degrees. So now you have 1:1 ratio. Simple subtraction after that.
 
Test_Angle = Absolute(Hour_Angle - Minute_Angle)


Needs a wrap-around check e.g.

  • HMI_Angle = 90 at 10:05:27 (AM or PM)
    • => Hour_Angle = ~303
      • => Minute_Angle = ~33
        • => Absolute(Hour_Angle - Minute_Angle) = 270
Algorithm yields 270, but absolute angle difference is 90

I think the point of the question is either how one handles the edge cases, or if one sees the edge cases.

.
 
Last edited:
Needs a wrap-around check e.g.

  • HMI_Angle = 90 at 10:05:27 (AM or PM)
    • => Hour_Angle = ~303
      • => Minute_Angle = ~33
        • => Absolute(Hour_Angle - Minute_Angle) = 270
Algorithm yields 270, but absolute angle difference is 90

I think the point of the question is either how one handles the edge cases, or if one sees the edge cases.

.

Good catch. Still waking up with my coffee. :)
 

Similar Topics

I received my Alexa Echo yesterday and I'm looking forward to automating the home. But I wondered just what other amazing things I can do with...
Replies
36
Views
9,786
So, I have my first real job interview this week...and I'm pretty nervous but also VERY excited. Just graduated as a junior industrial automation...
Replies
18
Views
6,804
I have been invited for an interview @Beumer group (Company) During the interview they will also ask me to make a program anyone here working in...
Replies
19
Views
6,314
About a year ago I was working for a local Industrial Electric/Automation company and we put together an IOT Remote Monitoring/Control box. After...
Replies
0
Views
1,213
Hey Guys, I landed an Interview with an electrical utility and I am wondering what questions I should ask the panel. They are using Schneider...
Replies
7
Views
1,735
Back
Top Bottom