CSES Solutions
#1637Dynamic Programming

Removing Digits

View on CSES

Solution

1637-Removing_Digits.cpp
1#include<bits/stdc++.h>
2using namespace std;
3#define int long long
4signed main(){
5  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
6  int n,res=0; cin>>n;
7  while(n){
8    int tn=n/10,v=n%10;
9    while(tn) v=max(v,tn%10),tn/=10;
10    n-=v,++res;
11  }
12  cout<<res<<'\n';
13  return 0;
14}

Editorial not yet generated for this problem. Run the editorial generation script to add hints and detailed explanations.