Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 674 |

@arpitsatnalika | 659 |

@tujhekya | 602 |

@code_it_ | 591 |

@prakharxyz | 583 |

@iamronak | 481 |

@Rahul Jadhav 1 | 466 |

@imnm | 466 |

@sivanandh03 | 464 |

@satyam0460 | 457 |

@18eumc107 | 443 |

Complete Leaderboard |

Given two numbers N and P, the task is to check if unit digit of N and N^{P}^{ }are the same or not.

**Example 1:**

**Input:** N = "2", P = 1
**Output:** 1
**Explanation:** Unit digit of 2^{1} is 2,
which is equals to 2

**Example 2:**

**Input:** N = "4", P = 2
**Output:** 0
**Explanation:** Unit digit of 4^{2} is 6,
which is not equals to 4

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **unitDigit() **which takes a string N and an integer P as inputs and returns the boolean value.

**Expected Time Complexity: **O(|P|).

**Expected Auxiliary Space: **O(1).

**Constraints:**

1 <= |N| <= 50

1 <= P <= 1000

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
The invariable units digit

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.