Skip to content

Commit f0f162e

Browse files
committed
Added more solutions inside hard category
Added more solutions inside hard category
1 parent 737681b commit f0f162e

File tree

5 files changed

+90
-6
lines changed

5 files changed

+90
-6
lines changed

LeetCodeSolutions/HardLevelSolutions/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<attribute name="maven.pomderived" value="true"/>
1313
</attributes>
1414
</classpathentry>
15-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
15+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
1616
<attributes>
1717
<attribute name="maven.pomderived" value="true"/>
1818
</attributes>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4-
org.eclipse.jdt.core.compiler.compliance=1.5
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
55
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
66
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
77
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8-
org.eclipse.jdt.core.compiler.source=1.5
8+
org.eclipse.jdt.core.compiler.source=1.8

LeetCodeSolutions/HardLevelSolutions/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
<artifactId>LeetCodeSolutions</artifactId>
88
<version>0.0.1-SNAPSHOT</version>
99
</parent>
10-
<groupId>com.javaaid.leetcode</groupId>
1110
<artifactId>HardLevelSolutions</artifactId>
12-
<version>0.0.1-SNAPSHOT</version>
1311
<name>HardLevelSolutions</name>
1412
<url>http://maven.apache.org</url>
1513
<properties>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
*
3+
*/
4+
package com.javaaid.solutions.hard.heaps;
5+
6+
import java.util.ArrayDeque;
7+
import java.util.Arrays;
8+
import java.util.Deque;
9+
10+
/**
11+
* @author Kanahaiya Gupta
12+
*
13+
*/
14+
public class SlidingWindowMaximum {
15+
16+
public static int[] maxSlidingWindow(int[] nums, int k) {
17+
if (nums.length == 0 || nums == null || k == 0)
18+
return new int[0];
19+
20+
int result[] = new int[nums.length - k + 1];
21+
Deque<Integer> window = new ArrayDeque<Integer>();
22+
int m = 0;
23+
for (int i = 0; i < nums.length; i++) {
24+
while (!window.isEmpty() && nums[window.peekLast()] < nums[i]) {
25+
window.pollLast();
26+
}
27+
while (!window.isEmpty() && window.peek() < i - k + 1) {
28+
window.poll();
29+
}
30+
window.offer(i);
31+
if (i >= k - 1) {
32+
result[m++] = nums[window.peek()];
33+
}
34+
}
35+
return result;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
*
3+
*/
4+
package com.javaaid.solutions.hard.twopointer;
5+
6+
import java.util.HashMap;
7+
8+
/**
9+
* @author Kanahaiya Gupta
10+
*
11+
*/
12+
public class MinimumWindowSubstring {
13+
14+
public String minWindow(String s, String t) {
15+
HashMap<Character, Integer> hmap = new HashMap<Character, Integer>();
16+
17+
for (char ch : t.toCharArray()) {
18+
hmap.put(ch, hmap.getOrDefault(ch, 0) + 1);
19+
}
20+
int counter = hmap.size();
21+
int begin = 0, end = 0, len = Integer.MAX_VALUE;
22+
String ans = "";
23+
while (end < s.length()) {
24+
char endChar = s.charAt(end);
25+
Integer count = hmap.get(endChar);
26+
if (count != null) {
27+
hmap.put(endChar, count - 1);
28+
if (hmap.get(endChar) == 0)
29+
counter--;
30+
}
31+
end++;
32+
33+
while (counter == 0) {
34+
char c = s.charAt(begin);
35+
if (hmap.get(c) != null) {
36+
hmap.put(c, hmap.get(c) + 1);
37+
if (hmap.get(c) > 0)
38+
counter++;
39+
}
40+
if (end - begin < len) {
41+
len = end - begin;
42+
ans = s.substring(begin, begin + len);
43+
}
44+
begin++;
45+
}
46+
}
47+
return ans;
48+
}
49+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy