Is my solution competent?


  • 0
    Q

    I saw how everyone was using n % 9 and faster solutions. I kinda did my the brute-force way. Would it be okay for interviews?

    func addDigits(num: Int) -> Int {
       var total = num
       var adding = 0
       
       while (total >= 0)
       {
           adding += total % 10
           total = total / 10
           
           if (total < 10)
           {
                if (total + adding < 10)
                {
                    break
                }
                
               adding += total % 10
    
               total = adding
               adding = 0
           }
       }
       
       return adding + total
    

    }


  • 0
    D

    Well, the purpose of the question is not to see if you can write brute-force solution code (you wouldn't be interviewing if you didn't know), so my guess is it wouldn't be okay for the interviews. If the interviewer was feeling generous, he might follow-up with "Could you do it without any loop/recursion in O(1) runtime?" If he/she wasn't, they'll just regard this one as "wrong answer" and move on to next question


  • 0
    Q

    I really dislike this type of response because you're zoning in on a singular detail part of my question that wasn't really relevant and gave me a generalized answer.

    That said, I didn't find your response helpful at all. It gave 0 insight. Why did you even bother to comment?


  • 0
    D

    You asked if your solution would be OK for interviews. How is my answer not relevant? How is it 'zoning in on a singular detail'? We're clearly not seeing things eye to eye here, so I'll leave at that.

    I'm sorry if you disliked my response, but honestly I'm pretty appalled by your comment as well. Why did I bother to comment? It was rather simple question that's about a week old and no one was answering, so I thought I'd share my thoughts. Let me ask you the same question. If you are going to flame on anyone who didn't give answers you want, why did you even bother to ask the question in the first place?


  • 0
    Q

    @dan56 Going through old emails and glanced on this thread. I'm extremely sorry for my behavior just over a year ago. I'm a little bit shocked at how defensive I got and just how little I was able to accept criticism.

    Your response was perfectly valid. If I was an interviewer, I would 100% have asked the question you proposed. Again, I apologize.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.