Compare commits

...

37 Commits

Author SHA1 Message Date
Sami 8292c346aa fix: 2 more challenges 2024-11-24 19:24:23 -05:00
Sami fb5f689af3 fix: ReversedString+Palindrom 2024-11-16 14:08:46 -05:00
Sami b79fe73ffb fix: ReversedString 2024-11-16 13:51:40 -05:00
Sami 47bab72ff3 fix: OneOne 2024-11-13 10:14:43 -05:00
Sami c93a26c059 fix: OneOne 2024-11-13 09:59:50 -05:00
Sami f8748fcbdf fix: numbersofAs 2024-11-12 12:36:29 -05:00
Sami ba2db6a59e fix: JumpingClounds 2024-11-12 10:25:03 -05:00
Sami 29251ff399 fix: counting Valleys 2024-11-09 06:08:14 -05:00
Sami 9c622c1aa4 fix: added a new challenge 2024-11-08 06:52:31 -05:00
Sami 525fa089b9 fix: added a new challenge 2024-11-07 10:14:35 -05:00
Sami 8906e857ea fix: added a new challenge 2024-11-07 10:14:19 -05:00
Sami 880f1d5854 reversingArrays 2024-11-05 06:25:41 -05:00
Sami 0e13691185 DecreasingScoresRanks 2024-11-04 09:55:00 -05:00
Zakaria a3dd8f3ddc nothingChanged 2024-11-02 19:29:05 +00:00
Sami 58f386f775 printTokensandCurlybraces 2024-11-02 15:03:46 -04:00
Sami e5e4195765 printTokensandCurlybraces 2024-11-02 15:03:37 -04:00
Sami c02fa16282 MakeAnagramMethod2 2024-10-25 23:12:19 -04:00
Sami 322aa305a3 MakeAnagram 2024-10-25 19:05:45 -04:00
Sami 019f62504b MODULO 10power9+7 2024-10-23 18:42:15 -04:00
Sami b9b9b18218 MODULO 10power9+7 2024-10-23 18:42:15 -04:00
Sami 5b38218d7a RatioSomething 2024-10-21 12:41:35 -04:00
Sami 317ce9d5b1 RatioSomething 2024-10-21 12:41:23 -04:00
Sami 0346f8e0be Paired colors 2024-10-15 12:36:50 -04:00
Sami 7ecd444efb adding old solved challenges 2024-10-15 11:03:57 -04:00
Sami fa5ac5e089 Tagless 2024-10-08 05:45:58 -04:00
Sami 9aab140ad1 hourGlassChallengeEnhaced 2024-10-06 18:55:33 -04:00
Sami fe8e7f65cd hourGlassChallengeEnhaced 2024-10-06 18:55:19 -04:00
Sami e103e5c7fc hourGlassChallenge 2024-10-06 16:56:36 -04:00
Sami 34b2a56e02 hourGlassChallenge 2024-10-06 16:55:45 -04:00
Sami d6d3ccd4df SingltonJAVA 2024-09-25 16:44:47 -04:00
Sami 9d5ed95bf7 anotherCha 2024-09-21 12:04:52 -04:00
Sami a66ffc8910 anotherCha 2024-09-21 12:04:52 -04:00
Zakaria f384067ac0 Delete .gitea/workflows/mvn-demo.yml 2024-09-20 01:05:29 +00:00
Sami df7794f8b1 codingChallenge
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
Gitea Actions Demo / GoBuild (push) Failing after 5s
2024-09-18 21:08:55 -04:00
Sami afc94ab8a8 codingChallenge 2024-09-18 21:08:39 -04:00
Sami 52f6f2a1a8 anotherOne
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 10s
Gitea Actions Demo / GoBuild (push) Failing after 8s
2024-09-13 17:23:54 -04:00
Sami 8c5ac774d2 anotherOne 2024-09-13 17:23:54 -04:00
175 changed files with 2750 additions and 40 deletions
-29
View File
@@ -1,29 +0,0 @@
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
GoBuild:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
java-version: '17'
distribution: 'temurin'
- run: mvn test
-11
View File
@@ -1,11 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Unnamed" type="Application" factoryName="Application" nameIsGenerated="true">
<option name="ALTERNATIVE_JRE_PATH" value="17" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="MAIN_CLASS_NAME" value="Amazon" />
<module name="MvnDemo" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
+23
View File
@@ -0,0 +1,23 @@
public class Alone {
public static void main(String[] args) {
int[] ar = { 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9 };
lonelyNum(ar);
}
public static void lonelyNum(int[] arr) {
for (int i = 0; i < arr.length; i++) {
int count = 0;
for (int k = 0; k < arr.length; k++) {
if (arr[i] == arr[k]) {
count++;
}
}
if (count == 1) {
System.out.println(arr[i]);
}
}
}
}
Binary file not shown.
+42
View File
@@ -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;
}
}
+3
View File
@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml
+11
View File
@@ -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
View File
@@ -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
View File
@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
+6
View File
@@ -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
View File
@@ -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>
+6
View File
@@ -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.
+32
View File
@@ -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";
}
}
+11
View File
@@ -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>
@@ -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$/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>
@@ -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>
+33
View File
@@ -0,0 +1,33 @@
import java.io.OutputStream;
import java.net.InetSocketAddress;
import com.sun.net.httpserver.HttpServer;
public class Application {
public static void main(String[] args) throws Exception {
int serverPort = 8084;
// Create an HTTP server and bind it to the specified port
HttpServer server = HttpServer.create(new InetSocketAddress(serverPort), 0);
// Create a context for the "/api/hello" endpoint
server.createContext("/api/hello", (exchange -> {
String respText = "Hello world"; // The response text
// Send the response headers (HTTP 200 OK, content length of the response)
exchange.sendResponseHeaders(200, respText.getBytes().length);
// Get the response body output stream and write the response to it
OutputStream outputStream = exchange.getResponseBody();
outputStream.write(respText.getBytes());
outputStream.flush();
// Close the exchange to finish the request
exchange.close();
}));
server.setExecutor(null); // Use default executor
server.start(); // Start the server
System.out.println("Server started on port " + serverPort);
}
}
Submodule
+1
Submodule ArraySum added at db216c988b
+1
Submodule BasketBallRecords added at fd9140c61f
+11
View File
@@ -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>
+50
View File
@@ -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
+11
View File
@@ -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>
+6
View File
@@ -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>
+6
View File
@@ -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.
+42
View File
@@ -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.
+35
View File
@@ -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;
}
}
+35
View File
@@ -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;
}
}
+96
View File
@@ -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>
+11
View File
@@ -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.
+67
View File
@@ -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;
}
}
+112
View File
@@ -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;
}
}
+3
View File
@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml
+6
View File
@@ -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>
+8
View File
@@ -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>
+6
View File
@@ -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.
+101
View File
@@ -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);
}
}
}
+11
View File
@@ -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.
+55
View File
@@ -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;
}
}
+26
View File
@@ -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");
}
}
}
+35
View File
@@ -0,0 +1,35 @@
import java.util.Scanner;
/**
* FibonacciSEQUENSE
*/
public class FibonacciSEQUENSE {
public static long[] fibCache;
public static void main(String[] args) {
// 1 1 2 3 5 8 13
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a number to get the corresponding Fibonacci Number: ");
int x = sc.nextInt();
fibCache = new long[1 + x];
for (int i = 0; i < x; i++) {
System.out.println(fibSequence(i));
}
sc.close();
}
public static long fibSequence(int n) {
if (n <= 1) {
return n;
}
if (fibCache[n] != 0) {
return fibCache[n];
}
long fibNum = (fibSequence(n - 1) + fibSequence(n - 2));
fibCache[n] = fibNum;
return fibNum;
}
}
+38
View File
@@ -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;
}
}
+23
View File
@@ -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;
}
}
+3
View File
@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml
+6
View File
@@ -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>
+8
View File
@@ -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>
+6
View File
@@ -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>
+25
View File
@@ -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 }));
}
}
+11
View File
@@ -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>
+2
View File
@@ -0,0 +1,2 @@
RoundGrades.class
Grades.iml
+3
View File
@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml
+11
View File
@@ -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
View File
@@ -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
View File
@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
+6
View File
@@ -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
View File
@@ -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>
+6
View File
@@ -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>
+35
View File
@@ -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;
}
}
+22
View File
@@ -0,0 +1,22 @@
/**
* Grains
*/
public class Grains {
public static void main(String[] args) {
System.out.println(grainsCount());
}
public static double grainsCount() {
// Calculate the number of grains of wheat on a chessboard given that the number
// on each square doubles.
double gCount = 0;
double grainOnCurrentSQ = 1;
for (int i = 1; i <= 64; i++) {
gCount += grainOnCurrentSQ;
grainOnCurrentSQ *= 2;
}
return gCount;
}
}
Binary file not shown.
+58
View File
@@ -0,0 +1,58 @@
import java.util.Scanner;
public class HourGlass {
/*
* 1 1 1 0 0 0
* 0 1 0 0 0 0
* 1 1 1 0 0 0
* 0 0 0 0 0 0
* 0 0 0 0 0 0
* 0 0 0 0 0 0
*/
public static void main(String[] args) {
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;
int total = -63;
for (int i = 0; i < rows - 2; i++) {
for (int j = 0; j < columns - 2; j++) {
int currentSum = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j]
+ arr[i + 2][j + 1] + arr[i + 2][j + 2];
total = Math.max(total, currentSum);
}
}
return total;
}
}
Binary file not shown.
+117
View File
@@ -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;
}
}
+29
View File
@@ -0,0 +1,29 @@
import java.io.*;
import java.util.*;
public class JavaList {
public static void main(String[] args) {
/*
* Enter your code here. Read input from STDIN. Print output to STDOUT. Your
* class should be named Solution.
*/
List<Integer> L = new ArrayList<>();
Scanner scan = new Scanner(System.in);
System.out.print("Enter the number of Queries: ");
int Q = scan.nextInt();
while (Q-- > 0) {
int N = scan.nextInt();
L.add(N);
}
int x = scan.nextInt();
int y = scan.nextInt();
L.add(x, y);
int xagain = scan.nextInt();
L.remove(xagain);
for (int i = 0; i < L.size(); i++) {
System.out.print(L.get(i) + " ");
}
scan.close();
}
}
+87
View File
@@ -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;
}
}
+24
View File
@@ -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());
}
}
}
+49
View File
@@ -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.
+30
View File
@@ -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;
}
}
+30
View File
@@ -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();
}
}
}
+3
View File
@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml
+11
View File
@@ -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
View File
@@ -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
View File
@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
+6
View File
@@ -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
View File
@@ -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>
+6
View File
@@ -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.
+39
View File
@@ -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);
}
}
+11
View File
@@ -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>

Some files were not shown because too many files have changed in this diff Show More