Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f11bbe0
Update MainLinkedList.java
Mukulbaid63 May 31, 2020
8bf083a
Update MyLinkedList.java
Mukulbaid63 May 31, 2020
ee772b4
Update MainClass.java
Mukulbaid63 Jun 1, 2020
6e9c44d
Update MyStack.java
Mukulbaid63 Jun 1, 2020
fe2ae06
Updated Comments
Mukulbaid63 Jun 1, 2020
be81fbd
Update MyStack.java
Mukulbaid63 Jun 1, 2020
b7c435f
Update MainClass.java
Mukulbaid63 Jun 1, 2020
6c3825c
Update README.md
Mukulbaid63 Jun 1, 2020
a24e23e
Update SubarrayWithZeroSum.java
Mukulbaid63 Jun 2, 2020
c18cead
Update README.md
Mukulbaid63 Jun 3, 2020
1aae50d
Update README.md
Mukulbaid63 Jun 5, 2020
0b5a250
Merge branch 'master' into master
Mukulbaid63 Jun 5, 2020
d356291
Update README.md
Mukulbaid63 Jun 5, 2020
25ce66a
Update MainClass.java
Mukulbaid63 Jun 5, 2020
0a699d2
Merge pull request #6 from Mukulbaid63/Mukulbaid63-patch-5
Mukulbaid63 Jun 5, 2020
59d07c2
Update MainClass.java
Mukulbaid63 Jun 6, 2020
b6a6c52
Update MainClass.java
Mukulbaid63 Jun 6, 2020
da871e7
Update MyArrayList.java
Mukulbaid63 Jun 7, 2020
fc6953c
Added Github video link
Mukulbaid63 Jun 8, 2020
d63b761
Update README.md
Mukulbaid63 Jun 8, 2020
332024c
Merge branch 'master' into master
Mukulbaid63 Jun 8, 2020
04b6cf3
Detect Loop in Linked List
Mukulbaid63 Sep 30, 2020
5a3809f
Create DetectLoop1.java
Mukulbaid63 Sep 30, 2020
ee775fb
Merge pull request #9 from Mukulbaid63/Mukulbaid63-patch-8
Mukulbaid63 Sep 30, 2020
a15b860
Create HeightCheckerLeetcode.java
Mukulbaid63 Sep 30, 2020
c67cef7
Merge pull request #10 from Mukulbaid63/Mukulbaid63-patch-9
Mukulbaid63 Sep 30, 2020
0009411
Added new Java 8 features important for placements
Oct 17, 2020
4f21bf5
Merge pull request #11 from namankhurpia/add_java_8_features
Mukulbaid63 Oct 27, 2020
e5657bb
Merge pull request #8 from Mukulbaid63/Mukulbaid63-patch-7
Mukulbaid63 Oct 27, 2020
6d0476a
Merge pull request #5 from Mukulbaid63/Mukulbaid63-patch-4
Mukulbaid63 Oct 27, 2020
1b3a7ef
Update README.md
Mukulbaid63 Oct 27, 2020
c3e2bcd
Update README.md
Mukulbaid63 Oct 27, 2020
7a723d0
Merge pull request #12 from Mukulbaid63/Mukulbaid63-patch-10
Mukulbaid63 Oct 27, 2020
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
103 changes: 103 additions & 0 deletions Java8Features/JavaEight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import java.util.*;
import java.util.function.Predicate;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import java.util.function.IntFunction;
import java.util.function.IntUnaryOperator;
import java.util.function.BinaryOperator;

interface TestInterf{
public void sumofvar(int a,int b);
}
interface NewInterf{
public int getlen(String s);
}
interface Fun{
public String convert(String s);
}

class JavaEight{
public static void main(String []args)
{
/*TestInterf sum = (a,b) -> System.out.println(a+b);
sum.sumofvar(3,4);

NewInterf obj = (s) -> s.length();
System.out.println(obj.getlen("naman"));

Fun obj2 = (s) -> s.toUpperCase();
System.out.println(obj2.convert("naman"));


Runnable r = () -> {
for(int i=0;i<10;i++)
{
System.out.println("child thread "+i);
}
};
Thread t = new Thread(r);
t.start();
for(int i=0;i<10;i++)
{
System.out.println("main thread"+i);
}


Predicate<String> pred = s -> s.length() > 10;
System.out.println(pred.test("asdc"));

BiPredicate<Integer,Integer> pred1 = (a,b)-> (a+b)>10;
System.out.println(pred1.test(12,5));



Function<Integer,Integer> fun = a -> a*a;
System.out.println(fun.apply(3));

BiFunction<String,String,Integer> func1 = (a,b) -> (a+b).length();
System.out.println(func1.apply("Hi ","trainees!"));

Function<String,String> f1 = s -> s.toUpperCase();
Function<String,String> f2 = s -> s.substring(0,2);
System.out.println(f1.andThen(f2).apply("tata"));
System.out.println(f1.compose(f2).apply("training session"));


Function<Integer,Integer> f3 = i -> i-2;
Function<Integer,Integer> f4 = i -> i*4;
System.out.println(f3.compose(f4).apply(3));

Function<Integer,Integer> f5 = i -> i*4;
Function<Integer,Integer> f6 = i -> i-2;
System.out.println(f5.compose(f6).apply(3));


Consumer<Double> con = a -> System.out.println(a/7);
con.accept(50.0);
BiConsumer<String,String> con1 = (a,b) -> System.out.println(a+b);
con1.accept("Naman","Khurpia");


Supplier<Date> s = () -> new Date();
System.out.println(s.get());



IntFunction<Integer> fun = a -> a*a;
System.out.println(fun.apply(25));


IntUnaryOperator uo = a -> a+10;
System.out.println(uo.applyAsInt(40));

*/

BinaryOperator<String> binary = (a,b) -> a+b;
System.out.println(binary.apply("Fri"+"day"));

}
}
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# DS-Algo
Implementation of Data structures and Algorithms at Apni Kaksha Java Placement Course.
# Data Structures-Algorithms
Implementation of Data structures and Algorithms at Apni Kaksha Java Placement Course.It covers all the important Data structures and Algorithms and also coding problems which are really important from the interview point of view.
<br>Anuj Bhaiya is the creator of this course.If you have any kind of doubts,you may reach him out:<a href="https://www.instagram.com/anuj.kumar.sharma/"></i>Anuj Kumar Sharma</a>
<br>
<h3>Installation</h3>
<ul>
<li><a href="https://www.oracle.com/java/technologies/javase-downloads.html"> JDK - Download</a></li>
<li><a href="https://www.eclipse.org/downloads/"> Eclipse IDE - Download </a></li>
</ul>

<br>
<h3>Topic Covered</h3>
<h3><u>Topics Covered:</u></h3>
<ul>
<li><a href="https://www.youtube.com/watch?v=A05CDzFJ010&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s&index=44&t=0s">Vector</a></li>
<li><a href ="https://www.youtube.com/watch?v=A05CDzFJ010&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s&index=44&t=0s">Stacks</a></li>
Expand All @@ -18,9 +18,11 @@ Implementation of Data structures and Algorithms at Apni Kaksha Java Placement C
<li><a href ="https://www.youtube.com/watch?v=APSx9uzhz6o&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s&index=52&t=0s">Maps</a></li>
<li><a href ="https://www.youtube.com/watch?v=pXk_0RX_d7c&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s&index=40&t=0s">Lists</a></li>
<li><a href ="https://www.youtube.com/watch?v=6KKIZL1wt8o&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s&index=43&t=0s">Linked List</a></li>
<li><a href ="https://www.youtube.com/watch?v=XDJKHtXJHBY&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s&index=49&t=0s">Interview Questions</a></li>
<li><a href ="https://www.youtube.com/watch?v=XDJKHtXJHBY&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s&index=49&t=0s">Important Interview Questions</a></li>
<li><a href ="https://www.youtube.com/watch?v=zSX7N5MolB8&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s&index=36&t=0s">Interfaces</a></li>
<li><a href ="https://www.youtube.com/watch?v=V_NVMqxcNaI&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s&index=47&t=0s">Doubly Ended Queue</a></li>
</ul>
<br>
<h3>YouTube Playlist (Video tutorial)- <a href ="https://www.youtube.com/watch?v=lxja8wBwN0k&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s">Java Data Structures and Algorithm</a></h3>

<h3>YouTube Playlist: <a href ="https://www.youtube.com/watch?v=lxja8wBwN0k&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s">Java ,Data Structures and Algorithms</a></h3>
<h3> All about Git and Github:<a href ="https://www.youtube.com/watch?v=iR5WIknxdkY&list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s&index=41&t=2406s">Git and Github</a></h3>
4 changes: 4 additions & 0 deletions deque/MainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ public static void main(String[] args) {

ArrayDeque<Integer> ad = new ArrayDeque<>();


//push method to push the element in the array double ended queue
ad.push(12);
ad.push(23);
ad.push(34);

//pop method to pop the element at the beginning of a array double ended queue

System.out.println(ad.pop());
System.out.println(ad.pop());
Expand Down
69 changes: 69 additions & 0 deletions interviewQuestions/DetectLoop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import java.util.*;
import java.io.*;


class Node
{
int data;
Node next;

Node(int x)
{
data = x;
next = null;
}
}

class LinkedList
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();

while(t--> 0)
{
int n = sc.nextInt();

int key = sc.nextInt();
Node head= new Node(key);
Node tail= head;

for(int i=0;i<n-1;i++)
{
key = sc.nextInt();
tail.next = new Node(key);
tail = tail.next;
}

//for testing,we can create a loop by inserting the next line
//head.next= head
//loops can be created in several ways

if(detectLoop(head))
System.out.println("True");
else
System.out.println("False");
}
}
public static boolean detectLoop(Node head)
{
Node fast=head;
Node slow=head;

while (slow!= null && fast!= null && fast.next!=null)
{
slow=slow.next;
fast=fast.next.next;
if(slow==fast)
{ // there exists a loop if and only if both fast and slow pointer point to a same one during traversal
return true;
}
}

return false;
}
}



69 changes: 69 additions & 0 deletions interviewQuestions/DetectLoop1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import java.util.*;
import java.io.*;


class Node
{
int data;
Node next;

Node(int x)
{
data = x;
next = null;
}
}

class LinkedList
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();

while(t--> 0)
{
int n = sc.nextInt();

int key = sc.nextInt();
Node head= new Node(key);
Node tail= head;

for(int i=0;i<n-1;i++)
{
key = sc.nextInt();
tail.next = new Node(key);
tail = tail.next;
}

//for testing,we can create a loop by inserting the next line
//head.next= head
//loops can be created in several ways

if(detectLoop(head))
System.out.println("True");
else
System.out.println("False");
}
}
public static boolean detectLoop(Node head)
{
Node fast=head;
Node slow=head;

while (slow!= null && fast!= null && fast.next!=null)
{
slow=slow.next;
fast=fast.next.next;
if(slow==fast)
{ // there exists a loop if and only if both fast and slow pointer point to a same one during traversal
return true;
}
}

return false;
}
}



16 changes: 16 additions & 0 deletions interviewQuestions/HeightCheckerLeetcode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public int heightChecker(int[] heights) {
int[] countArr = new int[101];
for(int h:heights){
countArr[h]++;
}
int res=0;
int curr =0;
for(int h:heights){
while(countArr[curr]==0)curr++;
if(h != curr) res++;
countArr[curr]--;
}
return res;
}
}
2 changes: 2 additions & 0 deletions interviewQuestions/SubarrayWithZeroSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static void main(String[] args) {
for (int element : a) {
set.add(sum);
sum += element;
//Zero sum will only exist if the cumulative sum of the elements excluding the current element
//and after including the current element are equal
if (set.contains(sum - k)) {
found = true;
break;
Expand Down
8 changes: 6 additions & 2 deletions linkedLists/MainLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ public static void main(String[] args) {

MyLinkedList<String> myLL = new MyLinkedList();


for (int i = 0; i < 10; i++) {
myLL.add(i + "added");
}
// add method use to add a element in the last node of the linked list
myLL.add(i + "added");

}
// print method use to print the linked list
myLL.print();
}

}

10 changes: 9 additions & 1 deletion linkedLists/MyLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class MyLinkedList<E> {


//E is the Class defining the type of the inputs accepted
Node<E> head;

public void add(E data) {
Expand All @@ -12,10 +14,14 @@ public void add(E data) {
return;
}

//initialising temp as head to traverse the Linked list without breaking the chain
Node<E> temp = head;
// control from loop exits as soon as next element becomes null
while (temp.next != null) {

temp = temp.next;
}
// adding the new node after reaching to the end of linked list
temp.next = toAdd;
}

Expand Down Expand Up @@ -48,7 +54,7 @@ public E removeLast() throws Exception {
temp = temp.next;
}
Node<E> toRemove = temp.next;
temp.next = null;
temp.next = null; // changing the pointer of temp.next from toRemove to null,and garbage collection is done automatically
return toRemove.data;
}

Expand All @@ -68,7 +74,9 @@ public static class Node<E> {
public E data;
public Node<E> next;

//constructor
public Node(E data) {

this.data = data;
next = null;
}
Expand Down
3 changes: 2 additions & 1 deletion lists/MyArrayList.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class MyArrayList {
public static void main(String[] args) {

List<String> fruits = new LinkedList();


//method to add the element in the list
fruits.add("Apple");
fruits.add("Orange");
fruits.add("Hi");
Expand Down
Loading