Compare commits
27 Commits
e103e5c7fc
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 8292c346aa | |||
| fb5f689af3 | |||
| b79fe73ffb | |||
| 47bab72ff3 | |||
| c93a26c059 | |||
| f8748fcbdf | |||
| ba2db6a59e | |||
| 29251ff399 | |||
| 9c622c1aa4 | |||
| 525fa089b9 | |||
| 8906e857ea | |||
| 880f1d5854 | |||
| 0e13691185 | |||
| a3dd8f3ddc | |||
| 58f386f775 | |||
| e5e4195765 | |||
| c02fa16282 | |||
| 322aa305a3 | |||
| 019f62504b | |||
| b9b9b18218 | |||
| 5b38218d7a | |||
| 317ce9d5b1 | |||
| 0346f8e0be | |||
| 7ecd444efb | |||
| fa5ac5e089 | |||
| 9aab140ad1 | |||
| fe8e7f65cd |
Binary file not shown.
@@ -0,0 +1,42 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class AnagramPeriod {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String a = sc.nextLine();
|
||||
String b = sc.nextLine();
|
||||
sc.close();
|
||||
|
||||
int totalDel = makeAnagram(a, b);
|
||||
System.out.println(totalDel);
|
||||
|
||||
}
|
||||
|
||||
private static int makeAnagram(String strOne, String strTwo) {
|
||||
// bacdc
|
||||
// dcbac
|
||||
// bacdc
|
||||
// dcbad
|
||||
|
||||
int[] a_frequency = new int[26]; // 26 numbers of letters in the alphabet.
|
||||
int[] b_frequency = new int[26]; // 26 numbers of letters in the alphabet.
|
||||
|
||||
// populate the frequence array for String strOne
|
||||
for (char c : strOne.toCharArray()) {
|
||||
a_frequency[c - 'a']++;
|
||||
}
|
||||
|
||||
// populate the frequence array for String strTwo
|
||||
for (char c : strTwo.toCharArray()) {
|
||||
b_frequency[c - 'a']++;
|
||||
}
|
||||
|
||||
// calculate the total number of deletions needed
|
||||
int deletion = 0;
|
||||
for (int i = 0; i < 26; i++) {
|
||||
deletion += Math.abs(a_frequency[i] - b_frequency[i]);
|
||||
}
|
||||
return deletion;
|
||||
}
|
||||
}
|
||||
Generated
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="accountSettings">
|
||||
<option name="activeRegion" value="us-east-1" />
|
||||
<option name="recentlyUsedRegions">
|
||||
<list>
|
||||
<option value="us-east-1" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/AngryProfessor.iml" filepath="$PROJECT_DIR$/AngryProfessor.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
@@ -0,0 +1,32 @@
|
||||
package AngryProfessor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AngryProf {
|
||||
public static void main(String[] args) {
|
||||
|
||||
List<Integer> a = new ArrayList<>();
|
||||
a.add(0);
|
||||
a.add(1);
|
||||
a.add(2);
|
||||
a.add(2);
|
||||
a.add(3);
|
||||
String answer = AngryProfessor(2, a);
|
||||
System.out.println(answer);
|
||||
}
|
||||
|
||||
public static String AngryProfessor(int k, List<Integer> a) {
|
||||
|
||||
int numOnTime = 0;
|
||||
for (int x : a) {
|
||||
if (x <= 0) {
|
||||
numOnTime++;
|
||||
}
|
||||
}
|
||||
if (numOnTime > k) {
|
||||
return "No";
|
||||
}
|
||||
return "Yes";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="AngryProfessor" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="accountSettings">
|
||||
<option name="activeRegion" value="us-east-1" />
|
||||
<option name="recentlyUsedRegions">
|
||||
<list>
|
||||
<option value="us-east-1" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
Generated
+5
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/AngryProfessor.iml" filepath="$PROJECT_DIR$/AngryProfessor.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="AngryProfessor" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Submodule
+1
Submodule ArraySum added at db216c988b
Submodule
+1
Submodule BasketBallRecords added at fd9140c61f
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,50 @@
|
||||
public class BeautifulDays {
|
||||
public static void main(String[] args) {
|
||||
|
||||
int x = beautifulDays(20 , 23, 2);
|
||||
System.out.println(x);
|
||||
}
|
||||
|
||||
public static int ReverseInt(int a){
|
||||
int revA = 0;
|
||||
int remainder = 0;
|
||||
while (a != 0){
|
||||
remainder = a % 10;
|
||||
revA *= 10;
|
||||
revA += remainder;
|
||||
a = a / 10;
|
||||
}
|
||||
return revA;
|
||||
}
|
||||
|
||||
public static int beautifulDays(int i, int j, int k) {
|
||||
|
||||
int beauxJours = 0;
|
||||
int m =0;
|
||||
int h =0;
|
||||
for (int x = i; x <= j; x++) {
|
||||
m = ReverseInt(x);
|
||||
|
||||
h = (Math.abs(x - m) % k);
|
||||
if (h == 0) {
|
||||
|
||||
beauxJours++;
|
||||
}
|
||||
}
|
||||
System.out.println(m);
|
||||
System.out.println(h);
|
||||
return beauxJours;
|
||||
}
|
||||
/*
|
||||
int count = 0 ;
|
||||
for (int l = i; l <= j; l++) {
|
||||
int m = reverseit(l);
|
||||
if (Math.abs(l-m) % k == 0) {
|
||||
count++;
|
||||
System.out.println(count+")"+l +"-"+reverseit(l) +"="+Math.abs(l-m)+"("+k+")");
|
||||
}
|
||||
}
|
||||
return count ;
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="accountSettings">
|
||||
<option name="activeRegion" value="us-east-1" />
|
||||
<option name="recentlyUsedRegions">
|
||||
<list>
|
||||
<option value="us-east-1" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/BeautifulDay.iml" filepath="$PROJECT_DIR$/BeautifulDay.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,42 @@
|
||||
import java.util.Arrays;
|
||||
|
||||
public class BinarySearch {
|
||||
public static void main(String[] args) {
|
||||
int[] seriesofNumbers = { 12, 14, 16, 17, 85, 5, 42, 23, 54, 96, 56, 45, 43, 32, 99, 33, 6, 77, 66, 98, 56, 43, 21,
|
||||
22 };
|
||||
|
||||
System.err.println(BinarySearchDo(seriesofNumbers, 33));
|
||||
}
|
||||
|
||||
public static int BinarySearchDo(int[] sortedNumbers, int wantedNumber) {
|
||||
// let's set the first and last indecies of the array
|
||||
int left = 0;
|
||||
int right = sortedNumbers.length - 1;
|
||||
// we sort the array just in case it is a series of random numbers
|
||||
Arrays.sort(sortedNumbers);
|
||||
for (int sortedNum : sortedNumbers) {
|
||||
System.out.print(sortedNum + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
// let's split the array into 2 and compare if the middle number is lower or
|
||||
// larger than the wanted number
|
||||
while (left <= right) {
|
||||
int middleIndex = (left + right) / 2;
|
||||
int middleNumber = sortedNumbers[middleIndex];
|
||||
System.out.println("The last index of this Array is " + right + " and the Middile index is " + middleIndex
|
||||
+ " ==> " + middleNumber);
|
||||
System.out.println("");
|
||||
if (wantedNumber == middleNumber) {
|
||||
System.out.println("");
|
||||
return middleIndex;
|
||||
}
|
||||
if (wantedNumber < middleNumber) {
|
||||
right = middleIndex - 1;
|
||||
}
|
||||
if (wantedNumber > middleNumber) {
|
||||
left = middleIndex + 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,35 @@
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BirdsMigration {
|
||||
public static void main(String[] args) {
|
||||
|
||||
List<Integer> BirdType = new ArrayList<>();
|
||||
BirdType.add(1);
|
||||
BirdType.add(3);
|
||||
BirdType.add(3);
|
||||
BirdType.add(2);
|
||||
BirdType.add(2);
|
||||
BirdType.add(2);
|
||||
|
||||
System.out.println(smallestID(BirdType));
|
||||
|
||||
}
|
||||
|
||||
private static int smallestID(List<Integer> birds) {
|
||||
int[] birdsTypeId = new int[6];
|
||||
int max = 0;
|
||||
|
||||
for (int bird : birds) {
|
||||
birdsTypeId[bird]++;
|
||||
max = Math.max(max, birdsTypeId[bird]);
|
||||
}
|
||||
for (int i = 0; i < birdsTypeId.length; i++) {
|
||||
if (birdsTypeId[i] == max) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BirdsMigration {
|
||||
public static void main(String[] args) {
|
||||
|
||||
List<Integer> BirdType = new ArrayList<>();
|
||||
BirdType.add(1);
|
||||
BirdType.add(3);
|
||||
BirdType.add(3);
|
||||
BirdType.add(2);
|
||||
BirdType.add(2);
|
||||
BirdType.add(2);
|
||||
|
||||
System.out.println(smallestID(BirdType));
|
||||
|
||||
}
|
||||
|
||||
private static int smallestID(List<Integer> birds) {
|
||||
int[] birdsTypeId = new int[6];
|
||||
int max = 0;
|
||||
|
||||
for (int bird : birds) {
|
||||
birdsTypeId[bird]++;
|
||||
max = Math.max(max, birdsTypeId[bird]);
|
||||
}
|
||||
for (int i = 0; i < birdsTypeId.length; i++) {
|
||||
if (birdsTypeId[i] == max) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Generated
+96
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="6a836e97-f059-4118-a4a0-e9b7b098ea99" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/.gitignore" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/aws.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/codeStyles/Project.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/BobConundrum/BobConundrum/.idea/.gitignore" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/BobConundrum/BobConundrum/.idea/aws.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/BobConundrum/BobConundrum/.idea/codeStyles/Project.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/BobConundrum/BobConundrum/.idea/codeStyles/codeStyleConfig.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/BobConundrum/BobConundrum/.idea/misc.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/BobConundrum/BobConundrum/.idea/modules.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/BobConundrum/BobConundrum/.idea/vcs.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/BobConundrum/BobConundrum/BobConundrum.iml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/BobConundrum/BobConundrum/BobConundrumSolution.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../fibonacciSQ.java" beforeDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="CodeStyleSettingsInfer">
|
||||
<option name="done" value="true" />
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
||||
</component>
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectCodeStyleSettingsMigration">
|
||||
<option name="version" value="2" />
|
||||
</component>
|
||||
<component name="ProjectId" id="2bpVKuzfFLmqaBBGOCQI3NxAqS5" />
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
<property name="project.structure.last.edited" value="Project" />
|
||||
<property name="project.structure.proportion" value="0.15" />
|
||||
<property name="project.structure.side.proportion" value="0.2" />
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="BobConundrumSolution" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="BobConundrum.BobConundrumSolution" />
|
||||
<module name="BobConundrum" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="BobConundrum.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Application.BobConundrumSolution" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="6a836e97-f059-4118-a4a0-e9b7b098ea99" name="Changes" comment="" />
|
||||
<created>1706911947169</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1706911947169</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
<option name="TAB_STATES">
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State />
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="BobConundrum" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
@@ -0,0 +1,67 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* BracketExpension
|
||||
*/
|
||||
public class BracketExpension {
|
||||
// You are given a string expression which consists of several comma separated
|
||||
// tokens
|
||||
// enclosed within opening ('{') and closing ('}') curly braces.
|
||||
// The string expression might or might not have a prefix before opening curly
|
||||
// brace('{') and
|
||||
// a suffix after closing curly brace ('}').
|
||||
// You have to return a list of strings as output for each comma separated item
|
||||
// as shown below in the examples.
|
||||
//
|
||||
// Example 1:
|
||||
// Input = "/2022/{jan,feb,march}/report"
|
||||
// Output = "/2022/jan/report"
|
||||
// "/2022/feb/report"
|
||||
// "/2022/march/report"
|
||||
//
|
||||
// Example 2:
|
||||
// Input = "over{crowd,eager,bold,fond}ness"
|
||||
// Output = "overcrowdness"
|
||||
// "overeagerness"
|
||||
// "overboldness"
|
||||
// "overfondness"
|
||||
//
|
||||
// Example 3:
|
||||
// Input = "read.txt{,.bak}"
|
||||
// Output = "read.txt"
|
||||
// "read.txt.bak"
|
||||
|
||||
public static void main(String[] args) {
|
||||
String tokens = "over{crowd,eager,bold,fond}ness";
|
||||
String tokeneez = "/2022/{jan,feb,march}/report";
|
||||
List<String> options = TokensListed(tokeneez);
|
||||
for (int i = 0; i < options.size(); i++) {
|
||||
System.out.println(options.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> TokensListed(String str) {
|
||||
List<String> ans = new ArrayList<>();
|
||||
// let's find the starting and the ending of the indecies of the curly braces;
|
||||
int startIndex = str.indexOf("{");
|
||||
int endIndex = str.indexOf("}");
|
||||
|
||||
if (startIndex == -1 || endIndex == -1 || startIndex > endIndex) {
|
||||
ans.add(str);
|
||||
return ans;
|
||||
}
|
||||
|
||||
// Extract the prefix, suffix and the options;
|
||||
String prefix = str.substring(0, startIndex);
|
||||
String suffix = str.substring(endIndex + 1);
|
||||
String options = str.substring(startIndex + 1, endIndex);
|
||||
|
||||
// Split the options by comma
|
||||
String[] tokens = options.split(",");
|
||||
for (String token : tokens) {
|
||||
ans.add(prefix + token + suffix);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* CountingValleys
|
||||
* An avid hiker keeps meticulous records of their hikes. During the last hike
|
||||
* that took exactly steps, for every step it was noted if it was an uphill, ,
|
||||
* or a downhill, step. Hikes always start and end at sea level, and each step
|
||||
* up or down represents a
|
||||
*
|
||||
* unit change in altitude. We define the following terms:
|
||||
*
|
||||
* A mountain is a sequence of consecutive steps above sea level, starting with
|
||||
* a step up from sea level and ending with a step down to sea level.
|
||||
* A valley is a sequence of consecutive steps below sea level, starting with a
|
||||
* step down from sea level and ending with a step up to sea level.
|
||||
*
|
||||
* Given the sequence of up and down steps during a hike, find and print the
|
||||
* number of valleys walked through.
|
||||
*
|
||||
* Example
|
||||
*
|
||||
* The hiker first enters a valley units deep. Then they climb out and up onto a
|
||||
* mountain
|
||||
*
|
||||
* units high. Finally, the hiker returns to sea level and ends the hike.
|
||||
*
|
||||
* Function Description
|
||||
*
|
||||
* Complete the countingValleys function in the editor below.
|
||||
*
|
||||
* countingValleys has the following parameter(s):
|
||||
*
|
||||
* int steps: the number of steps on the hike
|
||||
* string path: a string describing the path
|
||||
*
|
||||
* Returns
|
||||
*
|
||||
* int: the number of valleys traversed
|
||||
*
|
||||
* Input Format
|
||||
*
|
||||
* The first line contains an integer
|
||||
* , the number of steps in the hike.
|
||||
* The second line contains a single string , of
|
||||
*
|
||||
* characters that describe the path.
|
||||
*
|
||||
* Constraints
|
||||
*
|
||||
* Sample Input
|
||||
*
|
||||
* 8
|
||||
* UDDDUDUU
|
||||
*
|
||||
* Sample Output
|
||||
*
|
||||
* 1
|
||||
* Explanation
|
||||
*
|
||||
* If we represent _ as sea level, a step up as /, and a step down as \, the
|
||||
* hike can be drawn as:
|
||||
*
|
||||
* The hiker enters and leaves one valley.
|
||||
* BlogScoringEnvironmentFAQAbout UsSupportCareersTerms Of ServicePrivacy Policy
|
||||
*/
|
||||
public class CountingValleys {
|
||||
|
||||
// /\
|
||||
// _ / \_
|
||||
// \ /
|
||||
// \/
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Please enter the number of steps: ");
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int steps = sc.nextInt();
|
||||
sc.nextLine(); // consume the newline
|
||||
|
||||
System.out.println("The hiker is taking " + steps + " steps starting from sea level.");
|
||||
System.out.println("Please enter the path (U for up, D for down):");
|
||||
String path = sc.nextLine();
|
||||
|
||||
sc.close();
|
||||
System.out.println("Number of valleys: " + countingHikeValleys(steps, path));
|
||||
}
|
||||
|
||||
private static int countingHikeValleys(int steps, String path) {
|
||||
int valleysCount = 0;
|
||||
int seaLevel = 0;
|
||||
boolean inValley = false;
|
||||
|
||||
for (char step : path.toCharArray()) {
|
||||
if (Character.toUpperCase(step) == 'U') {
|
||||
seaLevel++;
|
||||
} else if (Character.toUpperCase(step) == 'D') {
|
||||
seaLevel--;
|
||||
}
|
||||
|
||||
// If we're below sea level and weren't before, we're entering a valley
|
||||
if (seaLevel < 0 && !inValley) {
|
||||
valleysCount++;
|
||||
inValley = true;
|
||||
}
|
||||
// If we're at or above sea level, we're no longer in a valley
|
||||
if (seaLevel >= 0) {
|
||||
inValley = false;
|
||||
}
|
||||
}
|
||||
|
||||
return valleysCount;
|
||||
}
|
||||
}
|
||||
Generated
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/DecreasingScores.iml" filepath="$PROJECT_DIR$/DecreasingScores.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,101 @@
|
||||
|
||||
/* DecreasingScore
|
||||
|
||||
* Comparators are used to compare two objects. In this challenge, you'll create
|
||||
* a comparator and use it to sort an array.
|
||||
*
|
||||
* The Player class is provided for you in your editor. It has
|
||||
* fields: a String and a
|
||||
*
|
||||
* integer.
|
||||
*
|
||||
* Given an array of
|
||||
* Player objects, write a comparator that sorts them in order of decreasing
|
||||
* score; if
|
||||
*
|
||||
* or more players have the same score, sort those players alphabetically by
|
||||
* name. To do this, you must create a Checker class that implements the
|
||||
* Comparator interface, then write an int compare(Player a, Player b) method
|
||||
* implementing the Comparator.compare(T o1, T o2) method.
|
||||
*
|
||||
* Input Format
|
||||
*
|
||||
* Input from stdin is handled by the locked stub code in the Solution class.
|
||||
*
|
||||
* The first line contains an integer,
|
||||
* , denoting the number of players.
|
||||
* Each of the subsequent lines contains a player's and
|
||||
*
|
||||
* , respectively.
|
||||
*
|
||||
* Constraints
|
||||
*
|
||||
* players can have the same name.
|
||||
* Player names consist of lowercase English letters.
|
||||
*
|
||||
* Output Format
|
||||
*
|
||||
* You are not responsible for printing any output to stdout. The locked stub
|
||||
* code in Solution will create a Checker object, use it to sort the Player
|
||||
* array, and print each sorted element.
|
||||
*
|
||||
* Sample Input
|
||||
*
|
||||
* 5
|
||||
* amy 100
|
||||
* david 100
|
||||
* heraldo 50
|
||||
* aakansha 75
|
||||
* aleksa 150
|
||||
*
|
||||
* Sample Output
|
||||
*
|
||||
* aleksa 150
|
||||
* amy 100
|
||||
* david 100
|
||||
* aakansha 75
|
||||
* heraldo 50
|
||||
*/
|
||||
import java.util.*;
|
||||
|
||||
// Write your Checker class here
|
||||
class Checker implements Comparator<Player> {
|
||||
|
||||
@Override
|
||||
public int compare(Player p1, Player p2) {
|
||||
if (p1.score == p2.score) {
|
||||
return p1.name.compareTo(p2.name);
|
||||
}
|
||||
return p2.score - p1.score;
|
||||
}
|
||||
}
|
||||
|
||||
class Player {
|
||||
String name;
|
||||
int score;
|
||||
|
||||
Player(String name, int score) {
|
||||
this.name = name;
|
||||
this.score = score;
|
||||
}
|
||||
}
|
||||
|
||||
public class DecreasingScore {
|
||||
public static void main(String[] args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int n = scan.nextInt();
|
||||
|
||||
Player[] player = new Player[n];
|
||||
Checker checker = new Checker();
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
player[i] = new Player(scan.next(), scan.nextInt());
|
||||
}
|
||||
scan.close();
|
||||
|
||||
Arrays.sort(player, checker);
|
||||
for (int i = 0; i < player.length; i++) {
|
||||
System.out.printf("%s %s\n", player[i].name, player[i].score);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
@@ -0,0 +1,55 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* EggDropping
|
||||
* You are given k identical eggs and you have access to a building with n
|
||||
* floors labeled from 1 to n.
|
||||
*
|
||||
* You know that there exists a floor f where 0 <= f <= n such that any egg
|
||||
* dropped at a floor higher than f will break,
|
||||
* and any egg dropped at or below floor f will not break.
|
||||
*
|
||||
* Each move, you may take an unbroken egg and drop it from any floor x (where 1
|
||||
* <= x <= n).
|
||||
* If the egg breaks, you can no longer use it. However, if the egg does not
|
||||
* break, you may reuse it in future moves.
|
||||
*
|
||||
* Return the minimum number of moves that you need to determine with certainty
|
||||
* what the value of f is.
|
||||
*
|
||||
* Example 1:
|
||||
*
|
||||
* Input: k = 1, n = 2
|
||||
* Output: 2
|
||||
* Explanation:
|
||||
* Drop the egg from floor 1. If it breaks, we know that f = 0.
|
||||
* Otherwise, drop the egg from floor 2. If it breaks, we know that f = 1.
|
||||
* If it does not break, then we know f = 2.
|
||||
* Hence, we need at minimum 2 moves to determine with certainty what the value
|
||||
* of f is.
|
||||
*
|
||||
*/
|
||||
public class EggDropping {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
int a = scanner.nextInt();
|
||||
int b = scanner.nextInt();
|
||||
scanner.close();
|
||||
System.out.println(minMoves(a, b));
|
||||
}
|
||||
|
||||
private static int minMoves(int k, int n) {
|
||||
// if n > f ==> eggs break
|
||||
// if n < f ==> eggs are good
|
||||
int min = 0;
|
||||
int[][] dp = new int[n + 1][k + 1];
|
||||
while (dp[min][k] < n) {
|
||||
min++;
|
||||
for (int i = 1; i <= k; i++) {
|
||||
dp[min][i] = dp[min - 1][i - 1] + dp[min - 1][i] + 1;
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ExtratFour {
|
||||
public static void main(String[] args) {
|
||||
lastFour();
|
||||
}
|
||||
|
||||
public static void lastFour() {
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Please enter your text");
|
||||
String text = sc.next();
|
||||
sc.close();
|
||||
System.out.println("");
|
||||
char[] four = text.toCharArray();
|
||||
for (int i = 0; i < four.length; i++) {
|
||||
System.out.print(four[i] + "\t");
|
||||
}
|
||||
System.out.println("");
|
||||
int size = four.length;
|
||||
int edge = size - 4;
|
||||
for (int i = edge; i < size; i++) {
|
||||
System.out.print(four[i] + "\t");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FindTheOne
|
||||
* given an array of ints, find the one that start with 1
|
||||
*/
|
||||
public class FindTheOne {
|
||||
public static void main(String[] args) {
|
||||
|
||||
int[] arr = { 1, 23, 123, 45, 67, 176 };
|
||||
System.out.println(OneOne(arr));
|
||||
}
|
||||
|
||||
// private static List<String> OneOne(int[] arr) {
|
||||
// List<String> Ones = new ArrayList<>();
|
||||
// String[] Convereted = new String[arr.length];
|
||||
// for (int i = 0; i < arr.length; i++) {
|
||||
// Convereted[i] = String.valueOf(arr[i]);
|
||||
// }
|
||||
// for (String str : Convereted) {
|
||||
// if (str.startsWith("1")) {
|
||||
// Ones.add(str);
|
||||
// }
|
||||
// }
|
||||
// return Ones;
|
||||
// }
|
||||
private static List<String> OneOne(int[] arr) {
|
||||
List<String> Ones = new ArrayList<>();
|
||||
for (int x : arr) {
|
||||
String str = Integer.toString(x);
|
||||
if (str.startsWith("1")) {
|
||||
Ones.add(str);
|
||||
}
|
||||
}
|
||||
return Ones;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Vowels {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Please enter your String here: ");
|
||||
String str = sc.nextLine();
|
||||
System.out.println(vowelsFound(str));
|
||||
sc.close();
|
||||
}
|
||||
|
||||
private static boolean vowelsFound(String str) {
|
||||
String vowels = "aeoui";
|
||||
for (char c : str.toLowerCase().toCharArray()) {
|
||||
if (vowels.indexOf(c) != -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Generated
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/GamePlatform.iml" filepath="$PROJECT_DIR$/GamePlatform.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* FinalSpeed
|
||||
*/
|
||||
public class FinalSpeed {
|
||||
|
||||
public static double calculateFinalSpeed(double initialSpeed, int[] inclinations) {
|
||||
/*
|
||||
* double finalSpeed = 0;
|
||||
* for (int speed : inclinations) {
|
||||
* double temp = initialSpeed;
|
||||
* initialSpeed = (-1 * speed) + temp;
|
||||
* finalSpeed = initialSpeed;
|
||||
* }
|
||||
*/
|
||||
double finalSpeed = initialSpeed;
|
||||
for (int speed : inclinations) {
|
||||
finalSpeed -= speed;
|
||||
}
|
||||
return finalSpeed;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(calculateFinalSpeed(60.0, new int[] { 0, 30, 0, -45, 0 }));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,2 @@
|
||||
RoundGrades.class
|
||||
Grades.iml
|
||||
Generated
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="accountSettings">
|
||||
<option name="activeRegion" value="us-east-1" />
|
||||
<option name="recentlyUsedRegions">
|
||||
<list>
|
||||
<option value="us-east-1" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Grades.iml" filepath="$PROJECT_DIR$/Grades.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,35 @@
|
||||
package Grades;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RoundGrades {
|
||||
public static void main(String[] args) {
|
||||
|
||||
List<Integer> notes = new ArrayList<>();
|
||||
|
||||
notes.add(34);
|
||||
notes.add(39);
|
||||
notes.add(54);
|
||||
notes.add(99);
|
||||
notes.add(29);
|
||||
notes.add(88);
|
||||
System.out.println(studentsGrades(notes));
|
||||
|
||||
}
|
||||
|
||||
public static List<Integer> studentsGrades(List<Integer> grades) {
|
||||
|
||||
List<Integer> results = new ArrayList<>();
|
||||
for (int grade : grades) {
|
||||
if (grade < 38) {
|
||||
results.add(grade);
|
||||
} else {
|
||||
int remainder = grade % 5;
|
||||
int roundNum = grade + 5 - remainder;
|
||||
results.add(roundNum - grade < 3 ? roundNum : grade);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
+27
-3
@@ -1,3 +1,5 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class HourGlass {
|
||||
|
||||
/*
|
||||
@@ -10,12 +12,34 @@ public class HourGlass {
|
||||
*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int[][] ar = { { 1, 1, 1, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0 }, { 1, 1, 1, 0, 0, 0 }, { 0, 0, 2, 4, 4, 0 },
|
||||
{ 0, 0, 0, 2, 0, 0 }, { 0, 0, 1, 2, 4, 0 } };
|
||||
int[][] ar = matrix();
|
||||
System.out.println(sumInt(ar));
|
||||
}
|
||||
|
||||
private static int[][] matrix() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("Please enter the 2D Matrix elements below:");
|
||||
System.out.println("Numbers of rows: ");
|
||||
int rows = scanner.nextInt();
|
||||
System.out.println("Numbers of Columns: ");
|
||||
int columns = scanner.nextInt();
|
||||
int[][] ar = new int[rows][columns];
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < columns; j++) {
|
||||
ar[i][j] = scanner.nextInt();
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < columns; j++) {
|
||||
System.out.print(ar[i][j] + "\t");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
scanner.close();
|
||||
return ar;
|
||||
}
|
||||
|
||||
private static int sumInt(int[][] arr) {
|
||||
int rows = arr.length;
|
||||
int columns = arr[0].length;
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,117 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* InfinityString
|
||||
* There is a string, , of lowercase English letters that is repeated infinitely
|
||||
* many times. Given an integer, , find and print the number of letter a's in
|
||||
* the first
|
||||
*
|
||||
* letters of the infinite string.
|
||||
*
|
||||
* Example
|
||||
*
|
||||
* The substring we consider is , the first characters of the infinite string.
|
||||
* There are
|
||||
*
|
||||
* occurrences of a in the substring.
|
||||
*
|
||||
* Function Description
|
||||
*
|
||||
* Complete the repeatedString function in the editor below.
|
||||
*
|
||||
* repeatedString has the following parameter(s):
|
||||
*
|
||||
* s: a string to repeat
|
||||
* n: the number of characters to consider
|
||||
*
|
||||
* Returns
|
||||
*
|
||||
* int: the frequency of a in the substring
|
||||
*
|
||||
* Input Format
|
||||
*
|
||||
* The first line contains a single string,
|
||||
* .
|
||||
* The second line contains an integer,
|
||||
*
|
||||
* .
|
||||
*
|
||||
* Constraints
|
||||
*
|
||||
* For of the test cases,
|
||||
*
|
||||
* .
|
||||
*
|
||||
* Sample Input
|
||||
*
|
||||
* Sample Input 0
|
||||
*
|
||||
* aba
|
||||
* 10
|
||||
*
|
||||
* Sample Output 0
|
||||
*
|
||||
* 7
|
||||
*
|
||||
*/
|
||||
public class InfinityString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// MY SOLUTION IS SLOW BUT IT WORKS
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Please enter your 'String' here and it must contains the letter A: ");
|
||||
String str = sc.nextLine();
|
||||
System.out.println("Please enter how many times you want to repeat that: ");
|
||||
int x = sc.nextInt();
|
||||
System.out.println(numsOfAs(str, x));
|
||||
sc.close();
|
||||
}
|
||||
|
||||
//
|
||||
// private static int numsOfAs(String str, int n) {
|
||||
// int numberOfAs = 0;
|
||||
// int x = n;
|
||||
// String newSTR = "";
|
||||
// int remeinder = n / str.length();
|
||||
// while (n > 0 && newSTR.toCharArray().length < n + remeinder) {
|
||||
// newSTR += str;
|
||||
// n--;
|
||||
// }
|
||||
//
|
||||
// char[] charNewstr = newSTR.toCharArray();
|
||||
// for (int i = 0; i < x; i++) {
|
||||
// if (charNewstr[i] == 'a') {
|
||||
// numberOfAs++;
|
||||
// }
|
||||
// }
|
||||
// return numberOfAs;
|
||||
//
|
||||
//
|
||||
private static int numsOfAs(String str, int n) {
|
||||
int numberOfAs = 0;
|
||||
int numRepeats = n / str.length();
|
||||
int remainder = n % str.length();
|
||||
|
||||
// Count the number of 'a' characters in the repeated string
|
||||
numberOfAs = countAs(str) * numRepeats;
|
||||
|
||||
// Count the number of 'a' characters in the remaining portion
|
||||
if (remainder > 0) {
|
||||
numberOfAs += countAs(str.substring(0, remainder));
|
||||
}
|
||||
|
||||
return numberOfAs;
|
||||
}
|
||||
|
||||
private static int countAs(String str) {
|
||||
int count = 0;
|
||||
for (char c : str.toCharArray()) {
|
||||
if (c == 'a') {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* JumpingClouds
|
||||
* There is a new mobile game that starts with consecutively numbered clouds.
|
||||
* Some of the clouds are thunderheads and others are cumulus. The player can
|
||||
* jump on any cumulus cloud having a number that is equal to the number of the
|
||||
* current cloud plus or
|
||||
*
|
||||
* . The player must avoid the thunderheads. Determine the minimum number of
|
||||
* jumps it will take to jump from the starting postion to the last cloud. It is
|
||||
* always possible to win the game.
|
||||
*
|
||||
* For each game, you will get an array of clouds numbered
|
||||
* if they are safe or
|
||||
*
|
||||
* if they must be avoided.
|
||||
*
|
||||
* Example
|
||||
* Index the array from . The number on each cloud is its index in the list so
|
||||
* the player must avoid the clouds at indices and . They could follow these two
|
||||
* paths: or . The first path takes jumps while the second takes . Return
|
||||
*
|
||||
* .
|
||||
*
|
||||
* Function Description
|
||||
*
|
||||
* Complete the jumpingOnClouds function in the editor below.
|
||||
*
|
||||
* jumpingOnClouds has the following parameter(s):
|
||||
*
|
||||
* int c[n]: an array of binary integers
|
||||
*
|
||||
* Returns
|
||||
*
|
||||
* int: the minimum number of jumps required
|
||||
*
|
||||
* Input Format
|
||||
*
|
||||
* The first line contains an integer
|
||||
* , the total number of clouds. The second line contains space-separated binary
|
||||
* integers describing clouds where
|
||||
*
|
||||
* .
|
||||
*
|
||||
* Constraints
|
||||
*
|
||||
* Output Format
|
||||
*
|
||||
* Print the minimum number of jumps needed to win the game.
|
||||
*
|
||||
* Sample Input 0
|
||||
*
|
||||
* 7
|
||||
* 0 0 1 0 0 1 0
|
||||
*
|
||||
* Sample Output 0
|
||||
*
|
||||
* 4
|
||||
*
|
||||
*/
|
||||
public class JumpingClouds {
|
||||
public static void main(String[] args) {
|
||||
|
||||
int[] steps = { 0, 0, 0, 0, 0, 1, 0 };
|
||||
System.out.println(JumpsCount(steps));
|
||||
}
|
||||
|
||||
private static int JumpsCount(int[] clounds) {
|
||||
|
||||
int jumps = 0;
|
||||
int i = 0;
|
||||
while (i < clounds.length - 1) {
|
||||
if (i + 2 == clounds.length || clounds[i + 2] == 1) {
|
||||
i++;
|
||||
jumps++;
|
||||
} else {
|
||||
i += 2;
|
||||
jumps++;
|
||||
}
|
||||
}
|
||||
return jumps;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* LinkedListed
|
||||
*/
|
||||
public class LinkedListed {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<String, Integer> linkHashMap = new LinkedHashMap<>();
|
||||
|
||||
linkHashMap.put("AMD", 8);
|
||||
linkHashMap.put("Apple", 12);
|
||||
linkHashMap.put("Intel", 10);
|
||||
System.out.println("Our hashlinkedMap is: " + linkHashMap);
|
||||
// get the value of a key in a hashlinkedMap
|
||||
System.out.println("The CPU cores on AMD is: " + linkHashMap.get("AMD"));
|
||||
|
||||
for (Map.Entry<String, Integer> entry : linkHashMap.entrySet()) {
|
||||
System.out.println(entry.getKey() + " " + entry.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* MakeAnagram
|
||||
*/
|
||||
public class MakeAnagram {
|
||||
|
||||
// Anagran is 2 words compose of the sames letters such LISTEN and SILENT, MUG
|
||||
// and GUM, RATE and TEAR etc...
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.print("Please enter the first String here: " + "\t");
|
||||
String str1 = sc.nextLine();
|
||||
System.out.print("Please enter the second String here: " + "\t");
|
||||
String str2 = sc.nextLine();
|
||||
sc.close();
|
||||
|
||||
System.out.println(DeletionCount(str1, str2));
|
||||
|
||||
}
|
||||
|
||||
private static int DeletionCount(String strOne, String strTwo) {
|
||||
int deletionCount = 0;
|
||||
|
||||
int[] Freqency = new int[26];
|
||||
strOne = strOne.toLowerCase();
|
||||
strTwo = strTwo.toLowerCase();
|
||||
|
||||
// fill the frequency for strOne chars
|
||||
for (int i = 0; i < strOne.length(); i++) {
|
||||
Freqency[strOne.charAt(i) - 'a']++;
|
||||
}
|
||||
|
||||
// fill the frequency for strTwo chars
|
||||
for (int i = 0; i < strTwo.length(); i++) {
|
||||
Freqency[strTwo.charAt(i) - 'a']--;
|
||||
}
|
||||
|
||||
// to calculate the deletion count we are going to do the absolute addition of
|
||||
// the strOne and strTwo
|
||||
|
||||
for (int x : Freqency) {
|
||||
deletionCount += Math.abs(x);
|
||||
}
|
||||
|
||||
return deletionCount;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,30 @@
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* MatchPairedColors
|
||||
*/
|
||||
public class MatchPairedColors {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int[] ar = { 1, 1, 1, 1, 3, 2, 2, 3, 4 };
|
||||
System.out.println(numberOfPairedSocks(ar));
|
||||
}
|
||||
|
||||
private static int numberOfPairedSocks(int[] arr) {
|
||||
int numofP = 0;
|
||||
HashMap<Integer, Integer> socksCount = new HashMap<>();
|
||||
for (int sock : arr) {
|
||||
if (socksCount.containsKey(sock)) {
|
||||
socksCount.put(sock, socksCount.get(sock) + 1);
|
||||
} else {
|
||||
socksCount.put(sock, 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (int count : socksCount.values()) {
|
||||
numofP += count / 2;
|
||||
}
|
||||
return numofP;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* MatrixInput
|
||||
*/
|
||||
public class MatrixInput {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Please enter the 2D Array here: ");
|
||||
System.out.println("Numbers of rows: ");
|
||||
int rows = sc.nextInt();
|
||||
System.out.println("Numbers of columns: ");
|
||||
int columns = sc.nextInt();
|
||||
int[][] arr = new int[rows][columns];
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < columns; j++) {
|
||||
arr[i][j] = sc.nextInt();
|
||||
}
|
||||
}
|
||||
System.out.println("");
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < columns; j++) {
|
||||
System.out.print(arr[i][j]);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="accountSettings">
|
||||
<option name="activeRegion" value="us-east-1" />
|
||||
<option name="recentlyUsedRegions">
|
||||
<list>
|
||||
<option value="us-east-1" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Min_Max.iml" filepath="$PROJECT_DIR$/Min_Max.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
@@ -0,0 +1,39 @@
|
||||
package Min_Max;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class MinMaxSum {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
List<Integer> arr = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
arr.add(sc.nextInt());
|
||||
}
|
||||
|
||||
sumMinMax(arr);
|
||||
sc.close();
|
||||
|
||||
sumMinMax(arr);
|
||||
}
|
||||
|
||||
public static void sumMinMax(List<Integer> arr) {
|
||||
Collections.sort(arr);
|
||||
|
||||
long minSum = 0;
|
||||
long maxSum = 0;
|
||||
|
||||
for (int i = 0; i < arr.size() - 1; i++) {
|
||||
minSum += arr.get(i);
|
||||
}
|
||||
|
||||
for (int i = 1; i < arr.size(); i++) {
|
||||
maxSum += arr.get(i);
|
||||
}
|
||||
|
||||
System.out.println(minSum + " " + maxSum);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="Min_Max" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="accountSettings">
|
||||
<option name="activeRegion" value="us-east-1" />
|
||||
<option name="recentlyUsedRegions">
|
||||
<list>
|
||||
<option value="us-east-1" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Min_Max.iml" filepath="$PROJECT_DIR$/Min_Max.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user