Skip to content

Problem solved#792

Open
harkhanid wants to merge 1 commit intosuper30admin:masterfrom
harkhanid:master
Open

Problem solved#792
harkhanid wants to merge 1 commit intosuper30admin:masterfrom
harkhanid:master

Conversation

@harkhanid
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Find the town Judge (Problem1.java)

Strengths:

  • The solution is correct and efficient, with optimal time and space complexity.
  • The code is concise and follows a logical approach.
  • The comments at the top correctly state the time and space complexity.

Areas for improvement:

  • The variable name "indegree" is slightly misleading because it is not just indegree (incoming edges) but a net trust count that also accounts for outgoing trust (by decrementing). A more accurate name might be "trustScore" or "netTrust".
  • The code uses indegree[edge[0]-1]-- and indegree[edge[1]-1]++ which correctly adjusts for 0-indexed arrays. However, it's important to note that the problem labels people from 1 to n. This is handled correctly, but the indexing might be confusing to some. Alternatively, you could create an array of size n+1 and index from 1 to n to avoid the constant adjustment, but the current approach is valid and efficient.
  • The base case if(n == 0) return -1; is unnecessary because the constraints state that n>=1. However, it doesn't hurt to have it for clarity.
  • Consider adding a comment explaining why the net trust count for the judge should be n-1: because the judge has no outgoing trust (so no decrements) and has incoming trust from all others (n-1 increments).

Overall, the solution is excellent. Just minor naming and commenting suggestions.

VERDICT: PASS


Ball in the Maze (Problem2.java)

Your solution is correct and efficient, with the same time and space complexity as the reference. Well done! Here are a few suggestions for improvement:

  1. Variable Naming: Consider using more descriptive variable names. For example, "cordinate" should be spelled "coordinate". Also, "nr" and "nc" are common, but "row" and "col" might be clearer.

  2. Initialization of Directions: The dirs array is declared as an instance variable, but it is constant and only used in this method. You can declare it inside the method or as a static final variable to avoid unnecessary instance state.

  3. Input Validation: While the problem constraints ensure that the maze has at least 2 empty spaces, it's good practice to check for null inputs. However, the current check for empty maze or zero columns is sufficient.

  4. Code Clarity: The while loop that rolls the ball until it hits a wall is correct, but you can add a comment to explain that it moves until it hits a wall or boundary.

  5. Modifying Input: Be aware that modifying the input maze might not be acceptable in some contexts. If required, you could use a separate visited array. However, since the reference solution does the same, it's acceptable here.

Overall, your solution is solid. Keep up the good work!

VERDICT: PASS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants