Skip to content

Instantly share code, notes, and snippets.

bachiri Taoufiq Abderrahman bachiri

Block or report user

Report or block bachiri

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bachiri
bachiri / GraphAdjacencyListRepresentation.java
Created Sep 5, 2019
Graph Adjacency list Representation
View GraphAdjacencyListRepresentation.java
import java.util.LinkedList;
public class GraphAdjacencyListRepresentation {
public static void main(String[] args) throws GraphRep.GraphException {
GraphRep graphRep = new GraphRep(6);
graphRep.addVertexTo(new GraphNode(4), new GraphNode(5));
graphRep.addVertexTo(new GraphNode(4), new GraphNode(1));
graphRep.addVertexTo(new GraphNode(4), new GraphNode(6));
@bachiri
bachiri / SlidingWindowMaximum.java
Created Sep 1, 2019
239. Sliding Window Maximum/Leetcode
View SlidingWindowMaximum.java
public class SlidingWindowMaximum {
public static void main(String[] args) {
int[] nums = {1, 3, -1, -3, 5, 3, 6, 7};
System.out.println("Maxs are " + Arrays.toString(maxSlidingWindow(nums, 3)));
}
public static int[] maxSlidingWindow(int[] nums, int k) {
List<Integer> result = new ArrayList<>();
for (int i = 0; i < nums.length; i++) {
@bachiri
bachiri / MergekSortedLists.java
Last active Aug 31, 2019
23. Merge k Sorted Lists /Leetcode
View MergekSortedLists.java
public class MergekSortedLists {
public static void main(String[] args) {
ListNode listNode = new ListNode(1);
listNode.next = new ListNode(4);
listNode.next.next = new ListNode(5);
ListNode secondListNode = new ListNode(1);
secondListNode.next = new ListNode(3);
secondListNode.next.next = new ListNode(4);
@bachiri
bachiri / SortCharactersByFrequency.java
Created Aug 31, 2019
451. Sort Characters By Frequency / Leetcode
View SortCharactersByFrequency.java
public class SortCharactersByFrequency {
public static void main(String[] args) {
System.out.println(frequencySort("Leetcode"));
}
public static String frequencySort(String s) {
HashMap<Character, Integer> map = new HashMap<>();
for (int i = 0; i < s.length(); i++) {
map.put(s.charAt(i), map.getOrDefault(s.charAt(i), 0) + 1);
}
@bachiri
bachiri / LengthLargestSubArray.java
Created Aug 31, 2019
Length of the largest subarray with contiguous elements
View LengthLargestSubArray.java
public class LengthLargestSubArray {
public static void main(String[] args) {
int arr[] = {1, 2, 3, 4, 5, 6, 10, 8, 7, 9};
System.out.println("Length of the largest subArray is " + lengthLargestSubArray(arr));
}
private static int lengthLargestSubArray(int[] arr) {
Arrays.sort(arr);
int counter = 0;
int maxCounter = 0;
You can’t perform that action at this time.