n = int(input()) c = 0 if n < 3: print(n) elif n in range(3, 13): print(n-1) elif n >= 13: for i in range(n): ele = str(i) if '3' in ele: c += 1 print(n-c) It is also helpful I hope
Problem 2 int n ; cin >> n; vector arr(n); for(auto & it : arr) cin >> it; int cnt = count(arr.begin(), arr.end() , 5); int rem = n - cnt; cnt /= 9; cnt *= 9; string ans = ""; while(cnt--) ans += '5'; while(rem--) ans += '0'; cout
problem 1....simple solution (in java) :- public static int countNumbersWithout3(int n) { int count = 0; for (int num = 1; num 0) { int digit = current % 10; if (digit == 3) { hasThree = true; break; // No need to continue checking if we found a 3 } current /= 10; } if (!hasThree) { count++; } } return count; }
int countNumbersWithThree(int num) { int count = 0; for (int i = 0; i < num; i++) { if (to_string(i).find('3') != string::npos) { count++; } } return count; }
n=input() count=0 for i in range(int(n)) : c=str(i) for j in range(len(c)) : if c[j] == '3' : count = count + 1 break a=int(n) print(a-count) will it be ok for time constraint mam
@@anshusharma-0498 well its standard digit dp problem.... the key idea is to create numbers for each index.... its hard to explain in cmmnts.... its better your try out "Classy Numbers" codeforces problem in order understand the basic idea of digit dp
Mam is there any Time complexity constraint in accenture coding questions??? Like can we do this question in O(n2) time complexity if i didn't remember this solution??
If u don't remember the optimised solution then you can always try for the brute force first. Some of the test cases will get passed. But always try to give a solution according to the time constraints given in the problem.
@@shrutigrover5092 Mam are there any time constraints in Accenture exam? Like mam i have seen various youtubers tell that acccenture coding questions doesn't have any time constraints..
JAVA ALSO HAVE PREDEFINED STRING FUNCTION : public class Main { public static void main(String[] args) { int n = 45; int result = countNot3(n); System.out.println(result); } public static int countNot3(int n) { int count = 0; for (int i = 1; i