Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions java-program/JumpGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Author: AKSHAY WAKHARE
* Date: 22 October 2021
*/


import java.util.*;
public class JumpGame{

public static void main(String args[]){
JumpGame s = new JumpGame();
int arr[] = {2,4,6,3,4,6};

if(s.isPosssible(arr)){
System.out.println(s.minJumps(arr));}
else{
System.out.println("Not Possible");
}
}


public boolean isPosssible(int[] nums) {

int n = nums.length;

//last index from where we can reach to end cell
//As from last index (n - 1) itself reach to end cell,
int lastIndex = n - 1;

for(int i = n - 1; i >= 0; i--){
if(i + nums[i] >= lastIndex){
lastIndex = i;
}
}

//check from 0 reach to end cell
return lastIndex == 0;
}



public int minJumps(int[] A) {
int jumps = 0, curEnd = 0, curFarthest = 0;
for (int i = 0; i < A.length - 1; i++) {
curFarthest = Math.max(curFarthest, i + A[i]);
if (i == curEnd) {
jumps++;
curEnd = curFarthest;
}
}
return jumps;
}
51 changes: 51 additions & 0 deletions java-program/ReverseNodesinKGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Author: AKSHAY WAKHARE
* Date: 22 October 2021
*/



// Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
// k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is.
// You may not alter the values in the list's nodes, only nodes themselves may be changed.


public /*class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}*/

//FUNCTION IMPLEMENTATION
public ListNode reverseKGroup(ListNode head, int k) {
int c=k;
ListNode h=head;
ListNode s=head;
ListNode p=null;
while(s!=null){
ListNode next=s.next;
s.next=p;
p=s;
k--;
if(k==0){
h.next=reverseKGroup(next,c);
return s;
}
s=next;
}

if(s==null&&k!=0){
s=p;
p=null;
while(s!=null){
ListNode next=s.next;
s.next=p;
p=s;
s=next;

}return p;
}return null;
}
}