Remainder with 7 | Practice | GeeksforGeeks

Given a number as string(n) , find the remainder of the number whe it is divided by 7

Example 1:
Input:
5
Output:
5
 
Example 2:
Input:
8
Output:
1

 
Your Task: 
You only need to complete the function remainderwith7() that takes string n as parameter and returns an integer which denotes the remainder of the number when its divided by 7
 
Constraints:
1<=length of n <=105
 
0
thaloravinash101 week ago
def remainderWith7(self, str):       a=int(str)       return a%7
0
adityapratyush1 month ago
Python Solution:
def remainderWith7(self, str):       return int(str) % 7
-1
aahankatiyar2 months ago
// why this code is wrong ??
 
 int remainderWith7(string n)   {       //Your code here              int size=n.length();       int i=size-1;      int  num=0;       int j=0;              while(i >=0)       {           int a=n[i]-'0';           num +=a*pow(10,j);           j++;           i--;       }              return (num % 7);   }
+1
akashindranagar3 months ago
**************************JAVA Solution ************************
class Solution{   // Complete the function   int remainderWith7(String num)   {       // Your code here        java.math.BigInteger rem;        java.math.BigInteger a=new  java.math.BigInteger(num);        java.math.BigInteger no1=new java.math.BigInteger("7");        rem=a.remainder(no1);        int result=rem.intValue();        return result;   }} 
0
mp333943 months ago
#python code (0.02 s)
class Solution:   #your task is to complete this function   #Function should return the required answer   #You are not allowed to convert string to integer   def remainderWith7(self, str):       #Code here       s = int(str)       return s%7
 
+6
sourabhsingh191220014 months ago
  int remainderWith7(string n)
{
    int rem = 0; 
    for(int i = 0; i < n.length(); i++)
    {
        rem = rem*10 + (n[i] - '0');
        rem = rem%7;
    }
    return rem;
}
0
sourabhsingh19122001
This comment was deleted.
+3
amoldongarwar4 months ago
where is wrong????
int remainderWith7(string n)   {       int rem;       int no=stoi(n);       rem=no%7;       return rem;   }
0
ankita12apr5 months ago
int remainderWith7(String num)   {       // Your code here       java.math.BigInteger b1 = new java.math.BigInteger(num);       java.math.BigInteger b2 = new java.math.BigInteger("7");       java.math.BigInteger number = b1.mod(b2);       int n = number.intValue();       return n;   }
0
komalk80096 months ago
https://www.geeksforgeeks.org/remainder-7-large-numbers/
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.