import 'dart:math'; class Solution { List shortestToChar(String s, String c) { List res = List.filled(s.length, 0); int c_position = s.length; for (int i = 0; i < s.length; i++) { if (s[i] == c) { c_positi } res[i] = (i - c_position).abs(); } for (int i = s.length - 1; i >= 0; i--) { if (s[i] == c) { c_position = i; } res[i] = min(res[i], (i - c_position).abs()); } return res; } } void main() { String s = "aaaabaaa"; String c = "b"; print(Solution().shortestToChar(s, c)); }