This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int count8(int n) { | |
if(n==0) | |
return 0; | |
int rem100=n%100; | |
int div=n/10; | |
int rem=n%10; | |
if(rem100==88){ | |
return 2+count8(div); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean nestParen(String str) { | |
int i= str.indexOf('('), j=str.lastIndexOf(')'); | |
if(i==-1 ^ j==-1){ | |
return false; | |
} | |
if(i==-1 && j==-1) | |
return true; | |
return nestParen(str.substring(i+1,j)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int countPairs(String str) { | |
if(str.length()<3) | |
return 0; | |
String sub=str.substring(0,3); | |
int n= checkSubstringForPair(sub); | |
return n+countPairs(str.substring(1,str.length())); | |
} | |
public int checkSubstringForPair(String sub){ | |
if(sub.charAt(0)==sub.charAt(2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean groupSum(int start, int[] nums, int target) { | |
if(target==0){ | |
return true; | |
} | |
if(start>=nums.length){ | |
return false; | |
} | |
if(groupSum(start+1, nums, target-nums[start])){ | |
return true; | |
}else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean groupSum5(int start, int[] nums, int target) { | |
if(start>=nums.length){ | |
return target==0; | |
} | |
if(nums[start]%5 == 0 && start<nums.length-1 && nums[start+1]!=1){ | |
return groupSum5(start+1, nums, target-nums[start]); | |
}else if(nums[start]%5==0){ | |
return(groupSum5(start+2, nums, target-nums[start])); | |
}else if(groupSum5(start+1, nums, target-nums[start])){ | |
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GfG | |
{ | |
// The task is to complete this function | |
int getId(int M[][], int n) | |
{ | |
java.util.Stack<Integer> stack= new java.util.Stack<Integer>(); | |
// Your code here | |
for(int i=0; i<n; i++){ | |
stack.push(i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mergesort{ | |
public static void main(String ... args){ | |
int [] array= {5, 4, 3, 2, 1, 0}; | |
printArray(mergerSort(copyOf(array,0, array.length))); | |
} | |
static void printArray(int [] array){ | |
for(int i: array){ | |
System.out.print(i+" "); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def partition(alist, first, last): | |
pivotValue= alist[first] | |
left= first+1 | |
right=last | |
done= False | |
while not done: | |
while alist[left]<pivotValue and left<right: | |
left=left+1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
public class Solution { | |
public static void main(String[] args) { | |
Scanner sc=new Scanner(System.in); | |
String s=sc.next(); | |
/* Enter your code here. Print output to STDOUT. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System: Host: sbsatter Kernel: 4.4.0-72-generic x86_64 (64 bit gcc: 5.4.0) | |
Desktop: Cinnamon 3.2.7 (Gtk 3.18.9-1ubuntu3.2) dm: mdm Distro: Linux Mint 18.1 Serena | |
Machine: System: Gigabyte product: N/A | |
Mobo: Gigabyte model: H170M-D3H-CF v: x.x Bios: American Megatrends v: F6 date: 03/07/2016 | |
CPU: Quad core Intel Core i5-6500 (-MCP-) cache: 6144 KB | |
flags: (lm nx sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx) bmips: 25535 | |
clock speeds: min/max: 800/3600 MHz 1: 800 MHz 2: 800 MHz 3: 800 MHz 4: 800 MHz | |
Graphics: Card: Intel Sky Lake Integrated Graphics bus-ID: 00:02.0 chip-ID: 8086:1912 | |
Display Server: X.Org 1.18.4 drivers: intel (unloaded: fbdev,vesa) | |
Resolution: 1366x768@59.79hz |