fork download
  1. class Solution {
  2. public:
  3. long long minCost(string s, vector<int>& cost) {
  4. int n = s.size();
  5. long long ans = LLONG_MAX; // Initialize to maximum value
  6.  
  7. // Try keeping each letter from 'a' to 'z'
  8. for (char ch = 'a'; ch <= 'z'; ch++) {
  9. long long sum = 0;
  10. bool found = false;
  11.  
  12. // Calculate cost of removing all other characters
  13. for (int i = 0; i < n; i++) {
  14. if (s[i] == ch) {
  15. // This character matches, so we keep it
  16. found = true;
  17. } else {
  18. // This character doesn't match, add its removal cost
  19. sum += cost[i];
  20. }
  21. }
  22.  
  23. // Update minimum cost if this letter exists in the string
  24. if (found) {
  25. ans = min(ans, sum);
  26. }
  27. }
  28.  
  29. return ans;
  30. }
  31. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:23: error: ‘string’ has not been declared
     long long minCost(string s, vector<int>& cost) {
                       ^~~~~~
prog.cpp:3:33: error: ‘vector’ has not been declared
     long long minCost(string s, vector<int>& cost) {
                                 ^~~~~~
prog.cpp:3:39: error: expected ‘,’ or ‘...’ before ‘<’ token
     long long minCost(string s, vector<int>& cost) {
                                       ^
prog.cpp: In member function ‘long long int Solution::minCost(int, int)’:
prog.cpp:4:19: error: request for member ‘size’ in ‘s’, which is of non-class type ‘int’
         int n = s.size();
                   ^~~~
prog.cpp:5:25: error: ‘LLONG_MAX’ was not declared in this scope
         long long ans = LLONG_MAX;  // Initialize to maximum value
                         ^~~~~~~~~
prog.cpp:5:25: note: ‘LLONG_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:1:1:
+#include <climits>
 class Solution {
prog.cpp:5:25:
         long long ans = LLONG_MAX;  // Initialize to maximum value
                         ^~~~~~~~~
prog.cpp:14:24: error: invalid types ‘int[int]’ for array subscript
                 if (s[i] == ch) {
                        ^
prog.cpp:19:28: error: ‘cost’ was not declared in this scope
                     sum += cost[i];
                            ^~~~
prog.cpp:25:23: error: ‘min’ was not declared in this scope
                 ans = min(ans, sum);
                       ^~~
stdout
Standard output is empty