We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Loading...
  • Practice
  • Compete
  • Jobs
  • Leaderboard
  • Hiring developers?
  1. Practice
  2. Algorithms
  3. Implementation
  4. Grading Students
  5. Discussions

Grading Students

  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial

    You are viewing a single comment's thread. Return to all comments →

  • cakerusk 3 years ago+ 7 comments

    Thanks. A lengthier solution might improve readability but compromise on lines of code (maintainability). Either way it doesn't affect runtime, so it comes down to a matter of personal preference I guess. :)

    0|
    ParentPermalink
    • sungmkim80 3 years ago+ 1 comment

      I don't agree that a lengthier answer would compromise maintainability. If you deal with a smaller chunk of code, it's easier to maintain as you can focus on a narrow logic.

      18|
      ParentPermalink
      • cakerusk 3 years ago+ 1 comment

        Probably not in this question but I pointed that out in general from an interview/development perspective. For this particular qs, it's only a matter of preference.

        1|
        ParentPermalink
        • JavaANDHannah 3 years ago+ 1 comment

          It's a terrible solution. Hello? Have you ever heard of the words, "RE-READ YOUR WORK?" Oh, and plus, it doesn't work. :)

          -24|
          ParentPermalink
          • cakerusk 3 years ago+ 2 comments

            It works perfectly fine.

            https://www.hackerrank.com/challenges/grading/submissions/code/39368045

            In case of issues, let me know.

            1|
            ParentPermalink
            • uniyal_guru 2 years ago+ 6 comments

              I have another solution for the same.

              static int[] solve(int[] grades){
                      // Complete this function
                      for(int i=0;i<grades.length;i++)
                      {
                        if(grades[i]>=38)
                        {
                             if(grades[i]+(5-grades[i]%5)-grades[i]<3)
                             grades[i]=(grades[i]+(5-grades[i]%5));
                        } 
                      }
                      return grades;
                  }
              
              7|
              ParentPermalink
              • doctorj0023 2 years ago+ 2 comments

                I did this with backward iteration and without your most inner If:

                for(int i = grades.Length-1; i >=0; i--)
                            {
                                if(grades[i] >= 38 && grades[i] % 5 >2)
                                {
                                    grades[i] = grades[i] + (5 - (grades[i] % 5));
                                }
                            }
                
                0|
                ParentPermalink
                • simonhaan 2 years ago+ 1 comment

                  What's the point of the backwards iteration? It practically won't make any difference.

                  9|
                  ParentPermalink
                  • ssaulakh2 2 years ago+ 0 comments

                    Yes it will! it will make the array go back wards and solution will be saved and appear in LIFO.

                    It is a stack implementation.

                    -9|
                    ParentPermalink
                • alexb760 1 year ago+ 3 comments

                  in your solution what happen if grade[i] = 67 them grades[i] % 5 = 7 and them 5-7 = -2 so 67 -2 = 65

                  -8|
                  ParentPermalink
                  • keickhoff1 1 year ago+ 0 comments

                    No, it will not pass the second condition of the if statement. Because 67 % 5 = 2 not 7.

                    0|
                    ParentPermalink
                  • harshrajan00 1 year ago+ 1 comment
                    [deleted]
                    0|
                    ParentPermalink
                    • harshrajan00 1 year ago+ 0 comments

                      As @keickhoff1 pointed out 67 remains 67.

                      0|
                      ParentPermalink
                  • anshulbadyal11 2 months ago+ 0 comments

                    please correct yourself and please do learn how to use modulus operator

                    0|
                    ParentPermalink
              • PareshSalunke 2 years ago+ 0 comments

                Your solution is perfectly fine but as a first draft. Whenever possible take out common operations and put it in a variable so next time what if the moderator said that multiple of 6 instead of 5 . you'll have to change at 2 places in your case but it may be a become bigger issue in complex chunk. Just saying. :)

                4|
                ParentPermalink
              • hard_system 2 years ago+ 0 comments

                very good, by the way it has to be grades.Length

                0|
                ParentPermalink
              • avi_ganguly94 2 years ago+ 1 comment

                in the inner if() , why did you do a grades[i] + blahBlahPivot - grades[i]? i mean, grades[i]-grades[i] is zero anyway so why bother?

                1|
                ParentPermalink
                • ssaulakh2 2 years ago+ 0 comments
                  [deleted]
                  0|
                  ParentPermalink
              • krishna_kumar_b1 2 years ago+ 0 comments

                this program have some error check your program

                0|
                ParentPermalink
              • tazpandey 1 year ago+ 1 comment

                Your answer is nice.But why you put -grades[i]<3 in if condition can you explain it.

                0|
                ParentPermalink
                • harshrajan00 1 year ago+ 0 comments

                  (5 - grades[i] % 5) < 3 if this is the condition you are talking about then the question says that If the difference between the grade and the next multiple of 5 is less than 2.

                  -2|
                  ParentPermalink
            • devin99 2 years ago+ 0 comments

              Your link doesn't work, like the code provided above

              0|
              ParentPermalink
    • rabbyalone 2 years ago+ 2 comments

      my solution

      static int[] solve(int[] grades)
              {            
                  int[] res = new int[grades.Length];
                  for (int i = 0; i < grades.Length; i++)
                  {
                      if (grades[i] % 5 > 2 && !(grades[i] < 38))              
                          res[i] = grades[i] + (5-grades[i]%5);                               
                      else               
                          res[i] = grades[i];
                     
                  }
                  return res;
              }
      
      6|
      ParentPermalink
      • aliriomambo 1 year ago+ 0 comments
        [deleted]
        1|
        ParentPermalink
      • van07 1 year ago+ 1 comment

        Would this be better? For reability only. Im not sure. It's really the same solution.

        int[] res = new int[grades.Length];

                for (int i = 0; i < grades.Length; i++)
                {
                                    int current = grade[i];
        
                    if (grades[i] % 5 > 2 && !(grades[i] < 38))              
                        current = grades[i] + (5-grades[i]%5);                               
        
                                 res[i] = current;
                }
        
                return res;
        
        2|
        ParentPermalink
        • skoffice47 1 month ago+ 0 comments

          Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks voyance gratuite immediate par telephone

          0|
          ParentPermalink
    • aaronederby 10 months ago+ 0 comments

      You are right. There is a pretty big epedimic of poor readability in coding these days. Some of these projects are pretty good proof of that.

      1|
      ParentPermalink
    • munna1991vikram 5 months ago+ 0 comments

      Get the complete information of windows 10 operating system by visiting here on this website. windows 10 free download Because this website provides us complete information of windows 10 operating system in your personal computer.

      -1|
      ParentPermalink
    • skoffice47 1 month ago+ 0 comments

      In the world of www, there are countless blogs. But believe me, this blog has all the perfection that makes it unique in all. I will be back again and again. Fortnite V bucks generator

      0|
      ParentPermalink
    • skoffice47 1 month ago+ 0 comments

      Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. viking appliance repair near me

      0|
      ParentPermalink
    • skoffice47 1 month ago+ 0 comments

      Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. Demir Leather

      0|
      ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature