Challenge

Project 1

1. public class Equillibrium Point

{

static int eqb point(int array[],int n)

{

int i,j;

int Lsum,r sum;

for (i=0;i

{

i sum=0;

for(j=0;j

Isum=lsum+array[j];

r sum=0;

r sum=r sum+array[j];

if(lsum==rsum)

return i;

}

2.Classs leaders in arrayy

{

void print leaders (int arr[],int size)

{

for (int i=0;i

{

int j;

for(j=i+1;j

{

if(arr[i]<=arr[j])

break;

}

if(j==size)

system.out.print(arr[i]] + "  ");

}

}

public static void main(stringg [] args)

{
int arr[]=new int[]{16,17,4,3,5,2}

int n=arr.length;

lead.print  leaders(arr,n);

}

}

ARGUEMENT    16174352       1752

                         12340          40

3..import java.util.regex.pattern;

public class exp

{

static sttring reverse words(stringg str)

{

pattern pattern =pattern.compile("\\s");

string [] temp=pattern.split(str);

string resultt=" ";

for(int i=0;i

{

if (i==temp.length -1)

result=temp[i]++result;

else

result= " " + tempp[i]+result;

}

return result;

}

public statiic void main (string[] args)

return -1;

}

public static void main(string [] args)

{

string s1="welcome to geeks for geeks";

system.out.printIn(reverse words (s1));

string s2="I  love java programming";

system.out.printIn(reverse words(s2));

}

}

Arguement I.like.this.program.very.much   pqr.mno

Print      much.very.program.this.like.i         mno.pqr

4.import  java.util.*;

class GFG

{

Static string remove duplicate (char str[],int n)

{

int iindex=0;

forr(int i=0;i

{

int j;

for(j=0;j++;j

{

if (str[i]==str[j])

{

break;

}

}

if(j==1)

{

str [indexx++]=str[i];

}

}

return string.valueof(Arrays.copy of(str,index))}

public stattic void main(string[] args)

{

char str[]= "geeks for geeks .to char array();

int n=str.lenngth;

systtem.out.printIn(remove duplicate(str,n));

}

}

ARGUEMENT SKILL LYNC SKILL LYNC COURSES

PRINT           SKILYNC     SKIL YNC OURE

5. Class GFG

{

Class node

{

int data;

node next;

public node(int data)'

{
this data=data;

this.next=null;

}

}

public void  push node(int data)

{

node new node=new node(data);

new node next=head;

head=new node;

}

public void print node()

{

node temp=head;

while(temp!=null)

{

system.out.print(temp.data + "->");

temp=tempp.next;

}

system.out.print("null" +"\n");

}

public int getlen()

{

int length=0;

node temp=head;

while (temp!=null)

{

length ++;

temp=temp.next;

}

return length;

}

public void print middle()

{

if(head!=null)

{

intt length=get len();

node temp=head;

int middle length=length/2;

while(middle length !=0)

{

temp=temp.next;

middle length --;

}

system.out.print("the middle element is ["temp .data +"]);

system.out.printIn();

}

}

GFG list=new GFG();

For (int i=5;i>=1;i--)

{

list.push node(i);

list.printnode();

listt.printMiddle();

}

}

}

6.class linked list

{

static node head;

static class node

{

int data;

node next;

node(int d)

{

data=d;

next=null;

}

}

node reverse(node node)

{

node prev=null;

niode current=node;

node next=null;

while (current !=null)

next=current.next;

current.next=prev;

prev=currentt;

current=nextt;

}

node=prev;

return node;

}

void print list(node node)

{

While (node!=null)

{

system.out.print(node.data + " " );

node=node.next;

}

}

public stattic void main (string[] args)

{

linked list list=new node(85);

list.head.next=new node(15);

list.head.next=new node(4);

list.head.next.next.next=new node(20);

system.out.printIn("given linked list");

list.printlist(head);

head=list.reverse(head);

system.out.printIn(" ");

system.out.printIn("Reversed linked list");

list.print List(head);

}

}

7. class linked list

{

node head;

class node

{

int data;

node next;

node(int d)

{

data=d;

next=null;

}

}

void pair wise swap()

{

node temp=head;

while(temp !=null &&temp.next!=null)

{

int k=temp.data;

temp.data=temp.next.data;

temp.next.data=k;

temp=temp.next.next;

}

}

public void push(int new_data)

{

node new _node=new node(new_data);

new_node.next=head;

head=new node;

}

void print list()

{

node temp=head;

while (temp !=null)

{

system.out.print(temp.data + " ");

temp=temp.next;

}

system.out.printIn();

}

public static void main(string args[])

{

linked list l list=new linked list();

l list.push(5);

l list.push(4);

l list.push(3);

l list.push(2);

l list.push(1);

system.out.printIn("LINKED list before calling pair wise swap());

l list.print list();

l list.pair wise swap();

system.out.printIn("LINKED list after calling pair wise swap() ");

l list.printlist();

}

}

8.import java.util.*;

class node

{

int data;

node next;

node(int data,node next)

{

this.data=data;

this.next=next;

}

}

public class my class

{

public static node convert list(int num)

{

node l=null;

while (num !=0){

l=new node(num%10, 1);

num=num/10;

}

return 1;

}

public static int to integer(node 1){

node curr=1;

int ans=0;

while(curr!=null){

ans=ans*10+curr.dataa;

curr=curr.next;

}

return ans;

}

public static node reverse node head){

node prev=head;

node curr=head.next;

while(curr!=null){

node next=curr.next;

curr.next=prev;

prev=curr;

curr=next;

}

head.next=null;

head=prev;

return head;

}

public static node add list(node11,node 12){

l1=reverse(l 1);

l 2=reverse(l 2);

int num1=to integer(  l 1);

int num 2=to integer(l 2);

node l 3=convert list (sum);

13=reverse(13);

return 13;

}

Public static void print list(node ans){

node curr=ans;

while (curr!=null){

system.out.print(curr.data +" " );

curr=curr.next;

}

}

public static void main(string []arrgs){

int x=243;

int y=564;

node l 1=convert list(x);

node l2=convert list(y);

node ans=add list(l 1,l 2);

print list (ans);

}

}

9.public class binary tree to DLL{

public static class node{

int data;

node left;

node right;

public node(int data){

this.data=data;

this.left=null;

this.right=null;

}

}

public node root;

node head,tail=null;

public void convertToDLL(Node node){

if(node==null)

return;

convert to DLL(node.left);

if(head==null){

head=tail=node;

}

else{

tail.right=node;

node.left=tail;

tail=node;

}

convert to DLL(node.right);

}

public void  display(){

node current=head;

if(head==null){

system.out.printIn("list is empty");

return;

}

system.out.printIn("nodes of generated doubly linked list");

while(current!=null){

system.out.print(current.data +" ");

current=current.right;

}

system.out.printIn();

}

public static void main(string []args){

binary tree to DLL bt=new binary treeTO DLL();

bt.root=new node(1);

bt.root=new node(2);

bt.root=new node(3);

bt.root.left.left=new node(4);

bt.root.left.right=new node(5);

bt.root.right.left=new node(6);

bt.root.right.right=new node(7);

bt. convertTo DLL (bt.root);

bt.display();

}

}

10. class GFG

{

Static void bell man ford(int graph[] [],int v,int E,int src)

{

int[] dis=new int[v];

for(inti=0;i

dis [i]=integer.max_value;

dis [src]=0;

for(int i=o;i

{

for(int j=0;j

{

IF(dis[graph[j][0] !=integer.max_value && dis graph[j][0]+graph[j][2]}

}

bellman ford(graph ,v,E,0);

}

}

11.import java.io.*;;

import java.math.*;

import java.util.*;

public class swap{

static int minimum swaps(int [] arr){

int swap=0;

boolean visited[]=new boolean[arr.length];

for(int i=0;i,arr.length;i++){

int j=1,cycle=0;

while(! visited[j]){

visited[j]=true;

j=arr[j]-1;

cycle++;

}

if(cycle!-0)

swap+cycle-1;

}

return swap;

}

public static void main(string [] args){

scanner scanner=new scanner (system.in);

int n=scanner.nextInt();

int[] arr=new int[n];

for(int i=0;i

arrr[i]=scanner.nextInt();

}

int res=minimum swaps(arr);

system.out.printIn(res);

scanner.close();

}

}

12.import java.util.*;

class solutions

{

static int min Ele;

static stack<  s=new stack<>();

static void push (int x)

{

if(s.is emoty()==true){
s.push(x);

minEle =x;

}

else if(x>min ele){

s.push(x);

}
else{

s.push(x);

}

eelse

{

s.push(2* x- min ele)

{

min ele=x;

}
}



Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.