Skip to content

Commit

Permalink
Added codes for 1 June
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Jun 1, 2024
1 parent 18f0cfb commit 4da5cd4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
48 changes: 48 additions & 0 deletions GeeksForGeeks/June/01-6-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//{ Driver Code Starts
import java.io.*;
import java.util.*;

class GFG {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t;
t = Integer.parseInt(br.readLine());
while (t-- > 0) {

String s;
s = br.readLine();

Solution obj = new Solution();
String res = obj.oddEven(s);

System.out.println(res);
}
}
}

// } Driver Code Ends



class Solution
{
public static String oddEven(String s)
{
// code here
int a[] = new int[27];
for(int i=0; i<s.length(); i++)
a[s.charAt(i)-'a' + 1]++;

int x=0, y=0;

for(int i=1; i<=26; i++)
{
if(a[i]!=0 && (i%2==0 && a[i]%2==0))
x++;
if(a[i]!=0 && (i%2!=0 && a[i]%2!=0))
y++;
}

return (x+y)%2 == 0 ? "EVEN" : "ODD";
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/June/01-6-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(|s|)
Space complexity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/June/01-6-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
10 changes: 10 additions & 0 deletions LeetCode/June/01-6-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution {
public int scoreOfString(String s) {
int ans = 0;

for (int i = 1; i < s.length(); ++i)
ans += Math.abs(s.charAt(i) - s.charAt(i - 1));

return ans;
}
}

0 comments on commit 4da5cd4

Please sign in to comment.