Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Some interview questions and solutions
# Some interview questions and solutions [![Maintainability](https://api.codeclimate.com/v1/badges/85cc07be5c6b99a815c6/maintainability)](https://codeclimate.com/github/gnomeria/interview-question-djava/maintainability)

>***These Java classes require Java 8***
> **_These Java classes require Java 8_**

The project uses Maven as its build and dependency tools, and jUnit as its
unit testing framework.
Expand All @@ -14,24 +14,24 @@ This will run all tests from `src/test/java/*`
This project's questions classes solutions ( `Q2.java`, `Q3.java`, `Q3_Optimize.java` ) DOES NOT have main class, so that it's
cleaner to see the solution, and running the test classes can be used instead.

********************************
---

## Question 1

- Write a method that takes a `String` and returns a `Boolean`.
- It should return True if the first character is an uppercase.
- You cannot use `String` APIs.

********************************
---

********************************
---

## Question 2

- Write a solution that returns an `Integer` with the total number of files
in a given folder including any files in its’ sub-folders (if any exist)
in a given folder including any files in its’ sub-folders (if any exist)

********************************
---

## Question 3

Expand All @@ -45,7 +45,7 @@ in a given folder including any files in its’ sub-folders (if any exist)
- The exit is represented by a `3`.
- Each path can only have two end points; **entrance** and **exit**. You cannot use the entrance or exit more than once foreach path.
- You have to step on every spot exactly once.
- You can only move like a King in chess(***horizontally*** or ***vertically*** but not diagonally)
- You can only move like a King in chess(**_horizontally_** or **_vertically_** but not diagonally)

### Example:

Expand All @@ -60,6 +60,6 @@ in a given folder including any files in its’ sub-folders (if any exist)

> The answer is 4

Your program should read from standard input with a series of integers with whitespace as delimiter. The ***first two integer*** represents the `width` and `height` of the maze. It will then befollowed by width * height more integers.Your output should be an integer which shows the total number of possiblepath
Your program should read from standard input with a series of integers with whitespace as delimiter. The **_first two integer_** represents the `width` and `height` of the maze. It will then befollowed by width \* height more integers.Your output should be an integer which shows the total number of possiblepath

********************************
---
8 changes: 6 additions & 2 deletions src/main/java/sami/interview/Q2.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ public class Q2 {
* @return
*/
private int GetNumberOfFiles(File file, int count) {
if(!file.exists()) return 0; //the provided file path does not exist
if(!file.exists()) {
return 0; //the provided file path does not exist
}
int current = 0;
if(file.isFile()) return 1;
if(file.isFile()) {
return 1;
}
else {
for (File f : file.listFiles()) {
current = current + GetNumberOfFiles(f, ++count);
Expand Down
1 change: 1 addition & 0 deletions src/test/java/sami/interview/Q1Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void shouldReturnTrueForUppercaseStrings() throws Exception {
assertTrue(Q1.isFirstCharUppercase("Jvm"));
assertTrue(Q1.isFirstCharUppercase("Github"));
assertTrue(Q1.isFirstCharUppercase("Sami"));
assertTrue(Q1.isFirstCharUppercase("Sami"));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/sami/interview/SolutionsTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void main(String[] args) {
Result result = JUnitCore.runClasses(classList.toArray(new Class<?>[classList.size()]));
if (result.wasSuccessful()) {
logger.info("All tests passed successfully. Tests ran for: {}ms", result.getRunTime());
return;
return 0;
}
result.getFailures().forEach(f -> logger.error("Error on: {}", f));
}
Expand Down