Skip to content

Commit a0c6d66

Browse files
committed
new commit
1 parent d403baf commit a0c6d66

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

Arrays/candyDistribution.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.util.HashSet;
2+
3+
public class candyDistribution {
4+
public static int distributeCandies(int[] candyType) {
5+
HashSet<Integer> set = new HashSet<>();
6+
for(int candy: candyType){
7+
set.add(candy);
8+
}
9+
return Math.min(set.size(), candyType.length/2);
10+
}
11+
public static void main(String[] args) {
12+
// take inputs accordingly
13+
}
14+
}

Strings/FirstUniqChar.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Strings;
2+
3+
import java.util.HashMap;
4+
5+
public class FirstUniqChar {
6+
public int firstUniqChar(String s) {
7+
HashMap<Character,Integer> map = new HashMap<>();
8+
for(int i=0; i<s.length(); i++){
9+
if(map.containsKey(s.charAt(i))){
10+
map.put(s.charAt(i), map.get(s.charAt(i))+1);
11+
}else{
12+
map.put(s.charAt(i), 1);
13+
}
14+
}
15+
for(int i=0; i<s.length(); i++){
16+
if(map.get(s.charAt(i))==1){
17+
return i;
18+
}
19+
}
20+
return -1;
21+
}
22+
public static void main(String[] args) {
23+
// take user input accordingly
24+
25+
}
26+
}

Strings/ValidPalindrome.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def isPalindrome(self, s: str) -> bool:
2+
lst = []
3+
for i in s:
4+
if i.isalnum():
5+
lst.append(i.lower())
6+
l,r = 0, len(lst)-1
7+
while(l<=r):
8+
if lst[l]!=lst[r]:
9+
return False
10+
l,r=l+1,r-1
11+
return True

0 commit comments

Comments
 (0)