Skip to content

Commit e07b519

Browse files
Day1 of 100daysof Code
1 parent ec6719b commit e07b519

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+332
-0
lines changed

Leetcode/.m.c.swp

12 KB
Binary file not shown.

Leetcode/MinimumRotated.class

924 Bytes
Binary file not shown.

Leetcode/MinimumRotated.java

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.util.*;
2+
public class MinimumRotated{
3+
public static void main(String[] args){
4+
Scanner cin=new Scanner(System.in);
5+
int n=cin.nextInt();
6+
int[] array=new int[n];
7+
for(int i=0;i<n;i++){
8+
array[i]=cin.nextInt();
9+
}
10+
System.out.println(MinimumRotation(array));
11+
}
12+
public static int MinimumRotation(int[] array){
13+
int left=0,right=array.length-1;
14+
if(array[left]<array[right]) return array[left];
15+
if(array.length==1) return array[left];
16+
while(left<right){
17+
// Find the inflectionPoint
18+
int midPoint=(left+right)/2;
19+
//check if midpoint is not the inflectionPoint
20+
if(array[midPoint]>array[midPoint+1] && midPoint<array.length) return array[midPoint+1];
21+
if(array[midPoint]<array[midPoint-1] && midPoint>0) return array[midPoint];
22+
if(array[midPoint]>array[left]){
23+
left=midPoint+1;
24+
}else{
25+
right=midPoint-1;
26+
}
27+
}
28+
return -1;
29+
}
30+
}

cdblocks/challenge1/AnyBase.class

-1.12 KB
Binary file not shown.
847 Bytes
Binary file not shown.
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Basic Trick:
3+
* nsp= 2*nrow-1
4+
* nst=n-nsp
5+
*/
6+
7+
import java.util.Scanner;
8+
public class HollowDiamond{
9+
public static void main(String[] args){
10+
Scanner cin=new Scanner(System.in);
11+
int n=cin.nextInt();
12+
int nrow=1;
13+
int nsp=2*nrow-1;
14+
int nst=n-nsp;
15+
while(nrow<=n){
16+
int cst=1;
17+
while(cst<=nst){
18+
System.out.print("*\t");
19+
cst++;
20+
}
21+
int csp=1;
22+
while(csp<=nsp){
23+
System.out.print("\t");
24+
csp++;
25+
}
26+
System.out.println();
27+
if(nrow<n/2){
28+
nsp=2*nrow-1;
29+
nst=n-nsp;
30+
}else{
31+
//nst=2*nrow-k;
32+
//nsp=n-nsp;
33+
}
34+
nrow++;
35+
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.*;
2+
public class ManmohanLovesPatternsI{
3+
public static void main(String[] args){
4+
Scanner cin=new Scanner(System.in);
5+
int n=cin.nextInt();
6+
int nst=1;
7+
int nrow=1;
8+
while(nrow<=n){
9+
//work
10+
int cst=1;
11+
while(cst<=nst){
12+
if((nst%2==0 && nst!=2) &&(cst > 1 && cst<nst)){
13+
System.out.print("0");
14+
}else{
15+
System.out.print("1");
16+
}
17+
cst++;
18+
}
19+
//prep
20+
System.out.println();
21+
nrow++;
22+
nst++;
23+
}
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.util.Scanner;
2+
public class ManmohanLovesPatternsII{
3+
public static void main(String[] args){
4+
Scanner cin=new Scanner(System.in);
5+
int n=cin.nextInt();
6+
int nst=1;
7+
int nrow=1;
8+
int pr=1;
9+
while(nrow<=n){
10+
//work
11+
int cst=1;
12+
while(cst<=nst){
13+
if(nst>2 && (cst>1 && cst<nst)){
14+
System.out.print("0");
15+
}
16+
else{
17+
System.out.print(pr);
18+
}
19+
cst++;
20+
}
21+
//prep
22+
System.out.println();
23+
nst++;
24+
nrow++;
25+
if(nrow>2)
26+
pr++;
27+
}
28+
}
29+
}
30+
31+
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.Scanner;
2+
public class PattenrTriangle{
3+
public static void main+(String[] args){
4+
5+
int nr;
6+
std::cin>>nr;
7+
int row=1;
8+
int val,nst=1,nsp=nr-1;
9+
while(row<=nr){
10+
val=1;
11+
int csp=1;
12+
while(csp<=nsp){
13+
std::cout<<" ";
14+
csp++;
15+
}
16+
int cst=1;
17+
while(cst<=nst){
18+
std::cout<<val<<" ";
19+
//prep
20+
if(cst<=nst/2){
21+
val++;
22+
}else{
23+
val--;
24+
}
25+
cst++;
26+
}
27+
//prep
28+
std::cout<<std::endl;
29+
nsp--;
30+
nst+=2;
31+
row++;
32+
}
33+
}
1001 Bytes
Binary file not shown.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.Scanner;
2+
public class PatternwithZeros{
3+
public static void main(String[] args){
4+
Scanner cin=new Scanner(System.in);
5+
int n=cin.nextInt();
6+
int nst=1;
7+
int nrow=1;
8+
while(nrow<=n){
9+
int cst=1;
10+
while(cst<=nst){
11+
if(nst>2 && (cst>=2 && cst<nst)){
12+
System.out.print("0\t");
13+
}
14+
else{
15+
System.out.print(nrow+"\t");
16+
}
17+
cst++;
18+
}
19+
System.out.println();
20+
nst++;
21+
nrow++;
22+
}
23+
}
24+
}
25+

cdblocks/challenge1/check.class

-831 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
-745 Bytes
Binary file not shown.
8.86 KB
Binary file not shown.

codes/java/practice/baiscs/pattern/x

-8.85 KB
Binary file not shown.

practice/LinkedList/Guvi.class

-1.1 KB
Binary file not shown.
406 Bytes
Binary file not shown.
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.util.*;
2+
class LinkedList{
3+
private class node{
4+
int data;
5+
node next;
6+
node(){
7+
this.data=0;
8+
this.next=null;
9+
}
10+
node(int item){
11+
this.data=item;
12+
this.next=null;
13+
}
14+
}
15+
private node head,tail;
16+
private int size=0;
17+
public void atBeg(int data){
18+
node temp=new node(data);
19+
temp.next=this.head;
20+
if(this.size==0) this.tail=temp;
21+
this.head=temp;
22+
this.size++;
23+
}
24+
//5->10->null
25+
//5->10->15->null
26+
public void atEnd(int data){
27+
node temp=new node(data);
28+
if(this.head==null){
29+
this.head=temp;
30+
}else{
31+
this.tail.next=temp;
32+
}
33+
this.tail=temp;
34+
this.size++;
35+
}
36+
public void atMiddle(int data,int index){
37+
node temp=new node(data);
38+
39+
public void display(){
40+
node temp=new node();
41+
temp=this.head;
42+
while(temp!=null){
43+
System.out.println(temp.data+" ");
44+
temp=temp.next;
45+
}
46+
}
47+
}
48+
public class InsertionAtMid{
49+
public static void main(String[] args){
50+
LinkedList list=new LinkedList();
51+
list.atBeg(10);
52+
list.atBeg(5);
53+
list.atEnd(15);
54+
list.display();
55+
}
56+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java.util.*;
2+
public class LinkedCollection{
3+
public static void main(String[] args){
4+
LinkedList<Integer> list=new LinkedList<Integer>();
5+
for(int i=1;i<10;i++){
6+
list.add(i);
7+
}
8+
System.out.println(Collections.reverse(list));
9+
}
10+
}
11+
507 Bytes
Binary file not shown.

practice/LinkedList/LinkedList.class

1.18 KB
Binary file not shown.
File renamed without changes.

codes/java/practice/arrays/RightArrayRotation.java practice/arrays/RightArrayRotation.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public static void main(String[] args){
1010
list.add(cin.nextInt());
1111
}
1212
int d=cin.nextInt();
13+
d%=list.size();
1314
RightRotation(list,0,list.size()-1);
1415
RightRotation(list,0,d-1);
1516
RightRotation(list,d,list.size()-1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*package whatever //do not write package name here */
2+
3+
import java.util.*;
4+
import java.lang.*;
5+
import java.io.*;
6+
7+
public class CyclicallyRotate {
8+
public static void main (String[] args) {
9+
Scanner cin=new Scanner(System.in);
10+
int t=cin.nextInt();
11+
while(t!=0){
12+
int n=cin.nextInt();
13+
ArrayList<Integer> list=new ArrayList<Integer>();
14+
for(int i=0;i<n;i++){
15+
list.add(cin.nextInt());
16+
}
17+
int d=n-1;
18+
Rotate(list,d);
19+
for(int i:list){
20+
System.out.print(i+" ");
21+
}
22+
t--;
23+
System.out.println();
24+
}
25+
}
26+
public static void Rotate(ArrayList<Integer> list, int d){
27+
d=d%list.size();
28+
reverse(list,0,d-1);
29+
reverse(list,d,list.size()-1);
30+
reverse(list,0,list.size()-1);
31+
}
32+
public static void reverse(ArrayList<Integer> list,int low,int high){
33+
while(low<high){
34+
Collections.swap(list,low,high);
35+
low++;
36+
high--;
37+
}
38+
}
39+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

spoj/2q

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def checkPrime(num):
2+
if(num<=1):
3+
return False
4+
if(num == 2 or num == 3):
5+
return True
6+
#if(num%2==0 or num%3==0):
7+
# return False
8+
for i in range(3,num+1):
9+
if(num%i==0):
10+
return False
11+
return True
12+
13+
if __name__ == "__main__":
14+
firstInput = int(input())
15+
secondInput = int(input())
16+
for i in range(firstInput, secondInput+1):
17+
if(checkPrime(i)==True):
18+
print(i)
19+

spoj/PrimeGen.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import math
2+
def checkPrime(num):
3+
if(num<=1):
4+
return False
5+
if(num == 2 or num == 3):
6+
return True
7+
if(num%2==0 or num%3==0):
8+
return False
9+
for i in range(3,int(math.sqrt(num))):
10+
if(num%i==0):
11+
return False
12+
return True
13+
14+
if __name__ == "__main__":
15+
loop=int(input())
16+
while(loop!=0):
17+
firstInput, secondInput = map(int, input().split())
18+
for i in range(firstInput, secondInput+1):
19+
if(checkPrime(i)==True):
20+
print(i)
21+
if(loop!=1):
22+
print()
23+
loop-=1
24+
File renamed without changes.

0 commit comments

Comments
 (0)