POTD Solutions | 20 Oct’ 23 | Form a number divisible by 3 using array digits Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report View all POTD Solutions Welcome to the daily solutions of our PROBLEM OF THE DAY (POTD). We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of basic mathematics but will also help you build up problem-solving skills. POTD 20th OctForm a number divisible by 3 using array digits Solve! Watch! POTD 20 October: Form a number divisible by 3 using array digitsYou will be given an array arr of integers of length N. You can construct an integer from two integers by treating the integers as strings and then concatenating them. For example, 19 and 4 can be used to construct 194 and 419.The task is to find whether it’s possible to construct an integer using all the digits of these numbers such that it would be divisible by 3.If it is possible then print 1 and if not print 0. Example: Input: arr[] = {40, 50, 90} Output: Yes Explanation: We can construct a number which is divisible by 3, for example 945000. So the answer is Yes. Input: arr[] = {1, 4} Output: No Explanation: The only possible numbers are 14 and 41, but both of them are not divisible by 3, so the answer is No. Form a number divisible by 3 using array digits using Divisibility by 3:The idea is based on the fact that a number is divisible by 3 if the sum of its digits is divisible by 3. So we simply find the sum of array elements. If the sum is divisible by 3, our answer is Yes, else No Below is the implementation of above approach: C++ class Solution { public: int isPossible(int n, int arr[]) { // Find remainder of sum when divided by 3 int remainder = 0; for (int i = 0; i < n; i++) remainder = (remainder + arr[i]) % 3; // Return true if remainder is 0. return (remainder == 0); } }; Java class Solution { static int isPossible(int n, int arr[]) { // Find remainder of sum when divided by 3 int remainder = 0; for (int i = 0; i < n; i++) remainder = (remainder + arr[i]) % 3; // Return true if remainder is 0. if (remainder == 0) return 1; return 0; } } Python3 class Solution: def isPossible(self, n, arr): # Find remainder of sum when divided by 3 remainder = 0 for i in range(0, n): remainder = (remainder + arr[i]) % 3 # Return true if remainder is 0. if (remainder == 0): return 1 return 0 Time Complexity: O(N), where N is the total number of elements in the arrayAuxiliary Space: O(1) POTD 20th OctForm a number divisible by 3 using array digitsRead Full Solution! Comment More infoAdvertise with us Next Article POTD Solutions | 20 Oct’ 23 | Form a number divisible by 3 using array digits V vaibhav_gfg Follow Improve Article Tags : Competitive Programming DSA GFG-POTD-Solutions Similar Reads Possible to make a divisible by 3 number using all digits in an array Given an array of integers, the task is to find whether it's possible to construct an integer using all the digits of these numbers such that it would be divisible by 3. If it is possible then print "Yes" and if not print "No". Examples: Input : arr[] = {40, 50, 90} Output : Yes We can construct a n 4 min read Number of digits to be removed to make a number divisible by 3 Given a very large number num (1 <= num <= 10^1000), print the number of digits that needs to be removed to make the number exactly divisible by 3. If it is not possible then print -1.Examples : Input: num = "1234"Output: 1Explanation: we need to remove one digit that is 1 or 4, to make thenum 13 min read Print digit's position to be removed to make a number divisible by 6 Given a number N, remove exactly one digit to make the number divisible by 6 (make it the largest possible). Print the position that has to be removed, If not possible then print -1. Examples: Input: 123 Output: 3 Explanation: Remove 3rd position element and hence the number is 12, which is divisibl 15 min read Number of substrings divisible by 8 but not by 3 Given a string of digits "0-9". The task is to find the number of substrings which are divisible by 8 but not by 3. Examples : Input : str = "888" Output : 5 Substring indexes : (1, 1), (1, 2), (2, 2), (2, 3), (3, 3). Input : str = "6564525600" Output : 15Recommended: Please solve it on âPRACTICE â 11 min read Number of substrings divisible by 6 in a string of integers Given a string consisting of integers 0 to 9. The task is to count the number of substrings which when convert into integer are divisible by 6. Substring does not contain leading zeroes. Examples: Input : s = "606". Output : 5 Substrings "6", "0", "6", "60", "606" are divisible by 6. Input : s = "48 9 min read Like