Our social:

Amazon SDE Hiring Challenge Problem Rhezo and divisibility by 7 Answer (solution )


Rhezo and divisibility by 7
Max. Marks 100
Rhezo is obsessed with the number 7 and likes numbers that are divisible by 7.
He has a big number of N digits and Q questions. In each of the question, he wants to find if the number formed by the string between indices Li and Ri is divisible by 7 or not. As he is very weak at programming, you should help him in this task.
Input:
First line contains the number consisting of N digits. Next line contains Q, denoting the number of questions. Each of the next Q lines contains 2 integers Li and Ri.
Output:
For each question, print "YES" or "NO", if the number formed by the string between indices Li and Ri is divisible by 7.
Constraints:
1N105
1Q105
1Li,RiN

Sample Input
(Plaintext Link)
357753
3
1 2
2 3
4 4
Sample Output
(Plaintext Link)
YES
NO
YES



Image result for amazon


Explanation
For the first query, number will be 35 which is clearly divisible by 7.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded if any testcase passes.
Allowed languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic




                  ANSWER HERE

Any doubts comment it below..!!