Skip to content

Instantly share code, notes, and snippets.

@roopeshsn
Created November 10, 2022 13:29
Show Gist options
  • Save roopeshsn/db706b0ab36ad3613a625d44895cc82f to your computer and use it in GitHub Desktop.
Save roopeshsn/db706b0ab36ad3613a625d44895cc82f to your computer and use it in GitHub Desktop.
package com.roopesh;
public class Main {
public static void main(String[] args) {
int ans = closureSum(6583);
System.out.println(ans);
}
public static int closureSum(int val) {
char[] chars = ("" + val).toCharArray();
int start = 0;
int end = chars.length - 1;
int ans = 0;
while(start < end) {
int temp = chars[start] + chars[end];
ans += temp;
start++;
end--;
}
if(start == end) {
ans += chars[start];
}
return ans;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment