• Latest Code...

    Featured Post

    Implementing Hilt in a Kotlin Android Jetpack Compose Project with MVVM Architecture

     In modern Android development, maintaining a scalable codebase can be challenging, especially when it comes to dependency management. Hilt,...

    Interview Question: find the angle between hour hand and minute hand

    Recently, I gave interview on the reputed company in silicon valley, I figure out the solution to that problem with solution in android.

    Question: 
    How do you find the angle between hour hand and minute hand with two input field, one is an hour and next one is minute and click the button find the angle, and calculate the angle between two input in textview.
    Time: 30 Minute

    Solution:
    They given me, Hour: 6  and Minute: 30 and output will be 15

    I took the base case for hour 12:00 (h = 12, m = 0) as a reference and followed these steps.

    • Calculate the angle made by hour hand with respect to 12:00 in h hours and m minutes.
    • Calculate the angle made by minute hand with respect to 12:00 in h hours and m minutes.
    • The difference between two angles is the angle between two hands.
    And I told them if I move minute hand  360 degree in 60 minute(or 6 degree in one minute) and move hour hand  360 degree in 12 hours(or 0.5 degree in 1 minute). 
    In hour hours and minute minutes, 

    #  minute hand would move to the (hour*60 + minute)*6 and 
    # hour hand would move to the(h*60 + m)*0.5.

    if you get the confuse above equation, please put the real hour and minute value check, it would be correct.

    Now, I started to coding in android

    Step 1: Layout
    The layout is very easy, in relative layout, you can just put textview for label and editext for input for both hour and minute and the button for click and gives output, finally, I put one textview for display out.

    Here is the Layout code, if you have any confusion:


    Now, I am going to write, the actual code that I have present during interview session:



    Here is the Acutal output of snapshot:





    I am still waiting for response!!
    Happy Coding !!!




    Contact Form

    Name

    Email *

    Message *