Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Atharv2433 authored Dec 3, 2024
1 parent bee03d5 commit 7d1a4fc
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions RequiredMoves.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package Strings;

import java.util.Scanner;

public class RequiredMoves {

public static int fun(String s){
int tm = 0;
char prev = 'a';
char arr[] = s.toCharArray();

for(char ch : arr){
int mini2 = Math.min(prev - 'a' + 'z' - ch + 1 , 'z' - prev + ch - 'a' + 1);
System.out.println(mini2);
int mini = Math.min(Math.abs(ch - prev) , mini2);

tm += mini + 1;
prev = ch;
}
return tm;
}
public static void main(String args[]){


Scanner sc = new Scanner(System.in);

String s = sc.next();

System.out.println(fun(s));

}

}

0 comments on commit 7d1a4fc

Please sign in to comment.