Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JavaAnnotations.java #10

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9c849e0
Another set of solutions
yanzv Jul 7, 2015
8563666
Java Domain Solutions
yanzv Jul 7, 2015
cbbaf85
More challenge and contest solutions
yanzv Jul 7, 2015
8790aeb
Week of code 16 solution
yanzv Jul 8, 2015
2ab73a8
New Challenges Solved
yanzv Oct 5, 2015
0de6c5c
Folder Updates
yanzv Oct 5, 2015
95af6bf
Added TaumAndBday Challenge
yanzv Oct 6, 2015
e24b932
Flowers Challenge
yanzv Oct 6, 2015
608c3d8
Flowers
yanzv Oct 7, 2015
c845c6e
Service Lane Challenge
yanzv Oct 8, 2015
ec20c2e
Cavity Map
yanzv Oct 8, 2015
e5b3163
Java 1D array (Hard) Challenge
yanzv Oct 14, 2015
841b1cb
Java1DArrayH Latest Version
yanzv Oct 14, 2015
e7a91e1
Zenefits CodeSprint
yanzv Dec 11, 2015
85c6c30
Add Java Domain Solutions
yanzv Dec 11, 2015
81fb862
Add Java Domain Solutions
yanzv Dec 11, 2015
6ebeada
All of my completed challenges
yanzv Dec 11, 2015
ae00769
Added Solutions from Indeed Contest
yanzv Dec 15, 2015
4965ded
Added Comments to Gretchen At Play Solution
yanzv Dec 15, 2015
1d797f6
Deleted .class file
yanzv Dec 15, 2015
bfa28db
Added more Solutions
yanzv Jul 7, 2016
48ce65f
Added TechHire CodeSprint solutions
yanzv Jul 26, 2016
74f8cdb
Added new solutions to Algorithms Domain
yanzv Oct 9, 2016
f18acc2
Added
yanzv Oct 9, 2016
30b10f0
Added Kangaroo Solution
yanzv Oct 10, 2016
14fa9e7
Another Two solutions Added
yanzv Oct 10, 2016
138df4c
Added Solutions From OpenBracket CodeSprint
yanzv Oct 17, 2016
57bdc20
Added Algorithms Domain Solutions
yanzv Oct 25, 2016
ed80586
Added Apple and Orange Solution
yanzv Oct 29, 2016
8875f7d
Added Minimum Spaces Solution
yanzv Nov 1, 2016
adf1052
Added Equilize the Array Solution
yanzv Nov 1, 2016
e1e6610
Added Flatland Space Stations Solution
yanzv Nov 2, 2016
54f6a31
Added Fair Rations Solution
yanzv Nov 2, 2016
bec77c7
Added Mini-Max Sum Solution
yanzv Nov 24, 2016
3e08fc8
Added Beautiful Days At The Movies Solution
yanzv Nov 24, 2016
18e9d0c
Added README
yanzv Nov 24, 2016
dc2d8ed
Created MatrixLayerRotation.java
mehtayash23 Feb 13, 2017
2ea8af5
Merge pull request #1 from mehtayash23/patch-1
Feb 13, 2017
4f438c3
Created CamelCase.java
mehtayash23 Feb 14, 2017
483f66f
Created BeautifulBinaryString.java
mehtayash23 Feb 14, 2017
2eb2480
Created DivisibleSumPairs.java
mehtayash23 Feb 14, 2017
b413f70
Created SaveThePrisoner.java
mehtayash23 Feb 14, 2017
24d28a2
Created StrangeCounter.java
mehtayash23 Feb 14, 2017
dac5f3c
Created TheBomberGame.java
mehtayash23 Feb 14, 2017
b46dede
Merge pull request #2 from mehtayash23/patch-1
Apr 27, 2017
da2fb2e
Update PatternSyntaxChecker.java
prabhakarankc Feb 23, 2020
4ad0ac2
Merge pull request #3 from prabhakarankc/patch-1
Feb 24, 2020
aeaa60e
Create GradingStudents.java
Szelmat Oct 6, 2020
89489e6
Merge pull request #4 from Szelmat/patch-1
Oct 7, 2020
c70b00f
Update JavaAnnotations.java
sumitgupta1312 Dec 1, 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
33 changes: 33 additions & 0 deletions Algorithms/Bit Manipulation/FlippingBits.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Flipping Bits

You will be given a list of 32 bits unsigned integers. You are required to output the list of the unsigned integers you get by flipping bits in its binary representation (i.e. unset bits must be set, and set bits must be unset).

Input Format

The first line of the input contains the list size T, which is followed by T lines, each line having an integer from the list.

Constraints

1≤T≤100
0≤integer<2^32
Output Format

Output one line per element from the list with the requested result.
*/

#import <Foundation/Foundation.h>


int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int numInput;
scanf("%d", &numInput);
for(int i=0;i<numInput;i++){
unsigned int num;
scanf("%u",&num);
printf("%u\n",(num^0xFFFFFFFF));
}

[pool drain];
return 0;
}
43 changes: 43 additions & 0 deletions Algorithms/Bit Manipulation/LonlyInteger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Lonely Integer
There are N integers in an array A. All but one integer occur in pairs. Your task is to find the number that occurs only once.

Input Format

The first line of the input contains an integer N, indicating the number of integers. The next line contains N space-separated integers that form the array A.

Constraints

1≤N<100
N % 2=1 (N is an odd number)
0≤A[i]≤100,∀i∈[1,N]
Output Format

Output S, the number that occurs only once.
*/

import java.io.*;
import java.util.*;

public class Solution {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
sc.nextLine();
ArrayList<String> alStr = new ArrayList<String>(Arrays.asList(sc.nextLine().split(" ")));
String answer="";
int pos = 0;
while(alStr.size()>1){
answer = alStr.get(0);
alStr.remove(0);
if(!alStr.contains(answer)){
break;
}else{
alStr.remove(answer);
}
pos++;

}
System.out.println(alStr.size()!=1?answer:alStr.get(0));
}
}
41 changes: 41 additions & 0 deletions Algorithms/Bit Manipulation/MaximizingXOR.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Maximizing XOR
Given two integers, L and R, find the maximal value of A xor B, where A and B satisfy the following condition:

L≤A≤B≤R
Input Format

The input contains two lines; L is present in the first line and R in the second line.

Constraints
1≤L≤R≤10^3

Output Format

The maximal value as mentioned in the problem statement.
*/

//Enter your code here. Read input from STDIN. Print output to STDOUT
#import <Foundation/Foundation.h>

int calculateMaximizingOR(int L,int R)
{
int maxVal = 0;
for(int i=L;i<=R;i++){
for(int j=i;j<=R;j++){
if((i^j)>maxVal){
maxVal=i^j;
}
}
}
return maxVal;
}

int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int L,R;
scanf("%d %d", &L,&R);
printf("%d\n",calculateMaximizingOR(L,R));

[pool drain];
return 0;
}
46 changes: 46 additions & 0 deletions Algorithms/Greedy/Flowers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Flowers
You and your K-1 friends want to buy N flowers. Flower number i has cost ci. Unfortunately the seller does not want just one customer to buy a lot of flowers, so he tries to change the price of flowers for customers who have already bought some flowers. More precisely, if a customer has already bought x flowers, he should pay (x+1)*ci dollars to buy flower number i.
You and your K-1 friends want to buy all N flowers in such a way that you spend the least amount of money. You can buy the flowers in any order.

Input:

The first line of input contains two integers N and K (K <= N). The next line contains N space separated positive integers c1,c2,...,cN.

Output:

Print the minimum amount of money you (and your friends) have to pay in order to buy all N flowers.
*/


import java.io.*;
import java.util.*;

public class Flowers {

public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
ArrayList <Integer> flowerPriceList = new ArrayList<Integer>();
int numFlowers = sc.nextInt();
int numFriends = sc.nextInt();
for(int i = 0; i<numFlowers;i++){
flowerPriceList.add(sc.nextInt());
}
// Sort the ArrayList in reverse order to start bying flowers from most expensive
Collections.sort(flowerPriceList,Collections.reverseOrder());
int flowersBought = 0;
int friendNum = 0;
int total = 0;
for(int price:flowerPriceList){
//itterate throught all the flower prices and calculate the total
total +=(flowersBought+1)*price;
friendNum++;
if(friendNum == numFriends){
//if all friends bought flowers reset the friend counter and restart the cycle
friendNum = 0;
flowersBought++;
}
}
System.out.println(total);
}
}
52 changes: 52 additions & 0 deletions Algorithms/Greedy/MarkAndToys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Mark And Toys

Mark and Jane are very happy after having their first kid. Their son is very fond of toys, so Mark wants to buy some. There are N different toys lying in front of him, tagged with their prices, but he has only $K. He wants to maximize the number of toys he buys with this money.

Now, you are Mark's best friend and have to help him buy as many toys as possible.

Input Format
The first line contains two integers, N and K, followed by a line containing N space separated integers indicating the products' prices.

Output Format
An integer that denotes maximum number of toys Mark can buy for his son.

Constraints
1<=N<=105
1<=K<=109
1<=price of any toy<=109
A toy can't be bought multiple times.

Sample Input

7 50
1 12 5 111 200 1000 10
Sample Output

4
*/

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class MarkAndToys {
public static void main(String[] args) {
Scanner stdin=new Scanner(System.in);
int n=stdin.nextInt(),k=stdin.nextInt();
int prices[]=new int[n];
for(int i=0;i<n;i++) prices[i]=stdin.nextInt();

int answer = 0;
Arrays.sort(prices);

int sum = 0;
int i = 0;
while(sum <=k){
sum+=prices[i++];
}
System.out.println(i-1);
}
}
58 changes: 58 additions & 0 deletions Algorithms/Greedy/PriyankaandToys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Priyanka and Toys

Little Priyanka visited a kids' shop. There are N toys and their weight is represented by an array W=[w1,w2,…,wN].
Each toy costs 1 unit, and if she buys a toy with weight w′, then she can get all other toys whose weight
lies between [w′,w′+4] (both inclusive) free of cost.

Input Format

The first line contains an integer N i.e. number of toys.
Next line will contain N integers, w1,w2,…,wN, representing the weight array.

Output Format

Minimum units with which Priyanka could buy all of toys.

Constraints
1≤N≤105
0≤wi≤104,where i∈[1,N]
Sample Input

5
1 2 3 17 10
Sample Output

3
*/

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class PriyankaAndToys {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
int arraySize = sc.nextInt();
int[]numArray = new int[arraySize];
for(int i = 0;i<arraySize;i++){
numArray[i] = sc.nextInt();
}

Arrays.sort(numArray);

int count = 1;
int currentToy=numArray[0];
for(int i = 1;i<numArray.length;i++){
if(numArray[i]>currentToy+4){
count++;
currentToy=numArray[i];
}
}
System.out.println(count);
}
}
83 changes: 83 additions & 0 deletions Algorithms/Greedy/TwoArrays.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Two Arrays

You are given two integer arrays, A and B, each containing N integers. The size of the array is
less than or equal to 1000. You are free to permute the order of the elements in the arrays.

Now here's the real question: Is there an permutation A', B' possible of A and B, such that, A'i+B'i ≥ K
for all i, where A'i denotes the ith element in the array A' and B'i denotes ith element in the array B'.


Input Format
The first line contains an integer, T, the number of test-cases. T test cases follow. Each test case has the following format:

The first line contains two integers, N and K. The second line contains N space separated integers, d
enoting array A. The third line describes array B in a same format.

Output Format
For each test case, if such an arrangement exists, output "YES", otherwise "NO" (without quotes).


Constraints
1 <= T <= 10
1 <= N <= 1000
1 <= K <= 109
0 <= Ai, Bi ≤ 109


Sample Input

2
3 10
2 1 3
7 8 9
4 5
1 2 2 1
3 3 3 4

Sample Output

YES
NO
*/

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class TwoArrays {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
int numTestCases = Integer.parseInt(sc.nextLine());
for(int i = 0;i<numTestCases;i++){
int arraySize = sc.nextInt();
int kValue = sc.nextInt();
sc.nextLine();
int []numArrayA = new int[arraySize];
int []numArrayB = new int[arraySize];
for(int k=0;k<arraySize;k++){
numArrayA[k] = sc.nextInt();
}
for(int k=0;k<arraySize;k++){
numArrayB[k] = sc.nextInt();

}
Arrays.sort(numArrayA);
Arrays.sort(numArrayB);

boolean isPossible = true;
for(int j=0;j<numArrayA.length;j++){
if(numArrayA[j]+numArrayB[numArrayB.length-1-j] < kValue){
isPossible = false;
break;
}
}
System.out.println(isPossible?"YES":"NO");

}
}
}
Loading