Skip to content

Commit d85ddc9

Browse files
committed
Solutions Added
1 parent 9d54756 commit d85ddc9

4 files changed

+141
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.*;
2+
import java.lang.*;
3+
import java.io.*;
4+
class GFG
5+
{
6+
public static void main (String[] args)
7+
{
8+
Scanner sc = new Scanner(System.in);
9+
int t = sc.nextInt();
10+
while (t-- != 0) {
11+
int n = sc.nextInt();
12+
int x = sc.nextInt();
13+
int a[] = new int[n];
14+
for (int i = 0; i < n; i++) {
15+
a[i] = sc.nextInt();
16+
}
17+
int f = 0;
18+
Set<Integer> s = new HashSet<>();
19+
for (int i = 0; i < a.length; i++) {
20+
if (s.contains(x - a[i])) {
21+
f = 1;
22+
break;
23+
}
24+
s.add(a[i]);
25+
}
26+
if (f == 1) {
27+
System.out.println("Yes");
28+
}
29+
else {
30+
System.out.println("No");
31+
}
32+
}
33+
34+
}
35+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.util.*;
2+
import java.lang.*;
3+
import java.io.*;
4+
class GFG
5+
{
6+
public static void main (String[] args)
7+
{
8+
Scanner sc = new Scanner(System.in);
9+
int t = sc.nextInt();
10+
while (t-- != 0) {
11+
int n = sc.nextInt();
12+
int x = sc.nextInt();
13+
int a[] = new int[n];
14+
for (int i = 0; i < n; i++) {
15+
a[i] = sc.nextInt();
16+
}
17+
Arrays.sort(a);
18+
int l = 0;
19+
int r = n - 1;
20+
int f = 0, sum = 0;
21+
while (l < r) {
22+
sum = a[l] + a[r];
23+
if (sum == x) {
24+
f = 1;
25+
break;
26+
}
27+
else if (sum < x) {
28+
l++;
29+
}
30+
else {
31+
r--;
32+
}
33+
}
34+
if (f == 1){
35+
System.out.println("Yes");
36+
}
37+
else {
38+
System.out.println("No");
39+
}
40+
41+
}
42+
43+
}
44+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class GfG
2+
{
3+
// Should print bottom view of tree with given root
4+
public void bottomView(Node root)
5+
{
6+
Map<Integer, Integer> tm = new TreeMap<>();
7+
int hd = 0;
8+
Queue<Node> q = new LinkedList<>();
9+
q.add(root);
10+
root.hd = 0;
11+
while (!q.isEmpty()) {
12+
Node temp = q.poll();
13+
hd = temp.hd;
14+
tm.put(hd, temp.data);
15+
if (temp.left != null) {
16+
q.add(temp.left);
17+
temp.left.hd = hd - 1;
18+
}
19+
if (temp.right != null) {
20+
q.add(temp.right);
21+
temp.right.hd = hd + 1;
22+
}
23+
}
24+
for (Map.Entry<Integer, Integer> m : tm.entrySet()) {
25+
System.out.print(m.getValue() + " ");
26+
}
27+
}
28+
}
29+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.*;
2+
import java.lang.*;
3+
import java.io.*;
4+
class GFG
5+
{
6+
public static void main (String[] args)
7+
{
8+
Scanner sc = new Scanner(System.in);
9+
int t = sc.nextInt();
10+
while (t-- != 0) {
11+
String s1 = sc.next();
12+
String s2 = sc.next();
13+
char ch3[] = new char[s1.length()];
14+
int count[] = new int[257];
15+
int k = 0;
16+
for (int i = 0; i < 257; i++) {
17+
count[i] = 0;
18+
}
19+
for (int i = 0; i < s2.length(); i++) {
20+
count[s2.charAt(i)]++;
21+
}
22+
for (int i = 0; i < s1.length(); i++) {
23+
if (count[s1.charAt(i)] == 0) {
24+
ch3[k++] = s1.charAt(i);
25+
}
26+
}
27+
for (int i = 0; i < k; i++) {
28+
System.out.print(ch3[i]);
29+
}
30+
System.out.println();
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)