Skip to content

feat: adds lesson_11 content and lesson_12 pre-work #383

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2025
Merged
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
27 changes: 27 additions & 0 deletions .github/workflows/check_lesson_11_java_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Check Lesson 11 Pull Request

on:
pull_request:
branches: [ "main" ]
paths:
- "lesson_11/arrays_java/**"

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Build Lesson 11 with Java
working-directory: ./lesson_11/arrays_java
run: ./gradlew check
28 changes: 28 additions & 0 deletions .github/workflows/check_lesson_11_ts_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check Lesson 11 Pull Request

on:
pull_request:
branches: [ "main" ]
paths:
- "lesson_11/arrays_ts/**"

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Build Lesson 11 with Node.js
working-directory: ./lesson_11/arrays_ts
run: |
npm ci
npm run check
14 changes: 14 additions & 0 deletions .github/workflows/check_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
- "lesson_06/quiz/**"
- "lesson_06/expression/**"
- "lesson_07/conditionals/**"
- "lesson_09/types/**"
- "lesson_10/libraries/**"
- "lesson_11/arrays_java/**"
- "lesson_11/arrays_ts/**"
jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -103,3 +107,13 @@ jobs:
run: |
npm ci
npm run compile

- name: Build Lesson 11 with Java
working-directory: ./lesson_11/arrays_java
run: ./gradlew assemble

- name: Build Lesson 11 with Node.js
working-directory: ./lesson_11/arrays_ts
run: |
npm ci
npm run compile
7 changes: 6 additions & 1 deletion lesson_11/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ Please review the following resources before lecture:

## Homework

- TODO(anthonydmays): Come up with something
- [ ] Complete methods in [Lesson11.java](./arrays_java/arrays_app/src/main/java/com/codedifferently/lesson11/Lesson11.java) and submit PR.
- [ ] Do pre-work for [lesson 12](/lesson_12/).

### Extra credit

- [ ] Complete TypeScript version of methods in [Lesson11.ts](./arrays_ts/src/lesson11.ts) and submit PR.
9 changes: 9 additions & 0 deletions lesson_11/arrays_java/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

5 changes: 5 additions & 0 deletions lesson_11/arrays_java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
64 changes: 64 additions & 0 deletions lesson_11/arrays_java/arrays_app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
application
eclipse
id("com.diffplug.spotless") version "6.25.0"
id("org.springframework.boot") version "3.4.0"
id("com.adarshr.test-logger") version "4.0.0"
}

apply(plugin = "io.spring.dependency-management")

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
// Use JUnit Jupiter for testing.
testImplementation("com.codedifferently.instructional:instructional-lib")
testImplementation("org.junit.jupiter:junit-jupiter:5.11.3")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.assertj:assertj-core:3.26.3")
testImplementation("at.favre.lib:bcrypt:0.10.2")

// This dependency is used by the application.
implementation("com.codedifferently.instructional:instructional-lib")
implementation("com.google.guava:guava:33.3.1-jre")
implementation("com.google.code.gson:gson:2.11.0")
implementation("org.projectlombok:lombok:1.18.30")
implementation("org.springframework.boot:spring-boot-starter")
}

application {
// Define the main class for the application.
mainClass.set("com.codedifferently.lesson11.Lesson11")
}

tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}


configure<com.diffplug.gradle.spotless.SpotlessExtension> {

format("misc", {
// define the files to apply `misc` to
target("*.gradle", ".gitattributes", ".gitignore")

// define the steps to apply to those files
trimTrailingWhitespace()
indentWithTabs() // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
})

java {
// don't need to set target, it is inferred from java

// apply a specific flavor of google-java-format
googleJavaFormat()
// fix formatting of type annotations
formatAnnotations()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.codedifferently.lesson11;

import java.util.List;

public class Lesson11 {

/**
* Provide the solution to LeetCode 1929 here:
* https://leetcode.com/problems/concatenation-of-array
*/
public int[] getConcatenation(int[] nums) {
return null;
}

/**
* Provide the solution to LeetCode 2942 here:
* https://leetcode.com/problems/find-words-containing-character/
*/
public List<Integer> findWordsContaining(String[] words, char x) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.codedifferently.lesson11;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;

class Lesson11Test {

@Test
public void testGetConcatenation() {
Lesson11 solution = new Lesson11();

// Test case 1
int[] nums1 = {1, 2, 1};
int[] expected1 = {1, 2, 1, 1, 2, 1};
int[] result1 = solution.getConcatenation(nums1);
assertArrayEquals(expected1, result1);

// Test case 2
int[] nums2 = {1, 3, 2, 1};
int[] expected2 = {1, 3, 2, 1, 1, 3, 2, 1};
int[] result2 = solution.getConcatenation(nums2);
assertArrayEquals(expected2, result2);

// Test case 3
int[] nums3 = {};
int[] expected3 = {};
int[] result3 = solution.getConcatenation(nums3);
assertArrayEquals(expected3, result3);

// Test case 4
int[] nums4 = {5};
int[] expected4 = {5, 5};
int[] result4 = solution.getConcatenation(nums4);
assertArrayEquals(expected4, result4);

// Test case 5
int[] nums5 = {0, 0, 0};
int[] expected5 = {0, 0, 0, 0, 0, 0};
int[] result5 = solution.getConcatenation(nums5);
assertArrayEquals(expected5, result5);
}

@Test
public void testWordsContainingChar() {
Lesson11 solution = new Lesson11();

// Test case 1
char ch1 = 'a';
String[] words1 = {"apple", "banana", "cherry", "date"};
List<Integer> expected1 = Arrays.asList(0, 1, 3);
List<Integer> result1 = solution.findWordsContaining(words1, ch1);
assertEquals(expected1, result1);

// Test case 2
char ch2 = 'z';
String[] words2 = {"apple", "banana", "cherry", "date"};
List<Integer> expected2 = Arrays.asList();
List<Integer> result2 = solution.findWordsContaining(words2, ch2);
assertEquals(expected2, result2);

// Test case 3
char ch3 = 'e';
String[] words3 = {"apple", "banana", "cherry", "date"};
List<Integer> expected3 = Arrays.asList(0, 2, 3);
List<Integer> result3 = solution.findWordsContaining(words3, ch3);
assertEquals(expected3, result3);

// Test case 4
char ch4 = 'a';
String[] words4 = {"", " ", "banana"};
List<Integer> expected4 = Arrays.asList(2);
List<Integer> result4 = solution.findWordsContaining(words4, ch4);
assertEquals(expected4, result4);
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading