Skip to content

Commit

Permalink
Added codes for 1 Mat
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed May 1, 2024
1 parent f0c12e0 commit 5bf7b27
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
109 changes: 109 additions & 0 deletions GeeksForGeeks/May/01-5-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//{ Driver Code Starts
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;

class Node {
char data;
Node next;

public Node(char data){
this.data = data;
next = null;
}
}

class GFG {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
Node head = null, tail = null;

char head_c = sc.next().charAt(0);
head = new Node(head_c);
tail = head;

while(n-- > 1){
tail.next = new Node(sc.next().charAt(0));
tail = tail.next;
}

Solution obj = new Solution();
//show(head);
show(obj.arrangeCV(head));

}
}

public static void po(Object o){
System.out.println(o);
}

public static void show(Node head){
while(head != null){
System.out.print(head.data+" ");
head = head.next;
}
System.out.println();
}
}

// } Driver Code Ends


/*
Structure of node class is:
class Node {
char data;
Node next;
public Node(char data){
this.data = data;
next = null;
}
}
*/
class Solution {

public Node arrangeCV(Node head){
//write code here and return the head of changed linked list
Node vowel = new Node('1');
Node v = vowel;

Node constant = new Node('1');
Node c = constant;


while(head!=null)
{
if(isVowel(head.data))
{
v.next = new Node(head.data);
v = v.next;
}
else
{
c.next = new Node(head.data);
c = c.next;
}

head = head.next;
}

v.next = constant.next;

return vowel.next;
}


public static boolean isVowel(char a)
{
if(a=='a' || a=='e' || a=='i' || a=='o' || a=='u')
return true;

return false;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/May/01-5-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)
2 changes: 2 additions & 0 deletions LeetCode/May/01-5-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(n)
6 changes: 6 additions & 0 deletions LeetCode/May/01-5-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Solution {
public String reversePrefix(String word, char ch) {
int i = word.indexOf(ch) + 1;
return new StringBuilder(word.substring(0, i)).reverse().append(word.substring(i)).toString();
}
}

0 comments on commit 5bf7b27

Please sign in to comment.