Skip to content

Commit

Permalink
add: two poiners
Browse files Browse the repository at this point in the history
  • Loading branch information
thutasann committed Feb 6, 2025
1 parent 2a82470 commit e120bb2
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 1 deletion.
60 changes: 60 additions & 0 deletions data_structures/src/KeyPatterns/SlidingWindow/MinMaxExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package KeyPatterns.SlidingWindow;

public class MinMaxExample {
public static void Examples() {
basic();
findingSmallerLarger();
dailyTempleratureMonitoring();
keepingValueWithinRange();
comparingTransactionLimits();
gamingHealh();
}

private static void gamingHealh() {
System.out.println("\n(Min Max) Gaming Health ==> ");
int health = 90, maxHealth = 100;
health = Math.min(health + 20, maxHealth);
System.out.println("Current Health ==> " + health);
}

private static void comparingTransactionLimits() {
System.out.println("\n(Min Max) Comparing Transation Limits ==> ");
double withdrawAmount = 500.0, balance = 300.0;
double maxWithdraw = Math.max(withdrawAmount, balance);
System.out.println("Allowed withdrawal: $" + maxWithdraw);
}

private static void keepingValueWithinRange() {
System.out.println("\n(Min Max) Keeping value within range ==> ");
int value = 120, min = 0, max = 100;
int clampedValue = Math.max(min, Math.min(value, max));
System.out.println("clampedValue ==> " + clampedValue);
}

private static void dailyTempleratureMonitoring() {
System.out.println("\n(Min Max) Daily Temperature Monitoring ==> ");
double templ1 = 18.5, temp2 = 22.1;
double lowest = Math.min(templ1, temp2);
double highest = Math.max(templ1, temp2);
System.out.println("Lowest temp : " + lowest);
System.out.println("Highest temp : " + highest);
}

private static void findingSmallerLarger() {
System.out.println("\n(Min Max) Finding the Smaller/Larger Number in a List ==> ");
int[] numbers = { 15, 3, 7, 22, 10 };
int minVal = numbers[0], maxVal = numbers[0];
for (int num : numbers) {
minVal = Math.min(minVal, num);
maxVal = Math.max(maxVal, num);
}
System.out.println("Min: " + minVal + ", Max: " + maxVal);
}

private static void basic() {
System.out.println("\n(Min Max) basic Usage ==> ");
int a = 10, b = 20;
System.out.println(Math.min(a, b));
System.out.println(Math.max(a, b));
};
}
26 changes: 25 additions & 1 deletion data_structures/src/KeyPatterns/SlidingWindow/Practice.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.TreeMap;

/**
* Sliding Window Practice
* Sliding Window and Two Pointers Practice
*/
public class Practice {
public static void Examples() {
Expand All @@ -18,6 +18,30 @@ public static void Examples() {
mergeTwoSortedArrays();
moveZeroToEnd();
System.out.println("\n(Two Pointers) TwoSum Sorted ==> " + Arrays.toString(TwoSumSorted()));
maxArea();
}

/**
* Container with Most Water
*/
public static void maxArea() {
System.out.println("\n(Two Pointers) Container with most water ==> ");
int[] height = { 1, 8, 6, 2, 5, 4, 8, 3, 7 };
int left = 0, right = height.length - 1;
int maxArea = 0;

while (left < right) {
int h = Math.min(height[left], height[right]);
int width = right - left;
maxArea = Math.max(maxArea, h * width);

if (height[left] < height[right])
left++;
else
right--;
}

System.out.println("Answer => " + maxArea);
}

/**
Expand Down
34 changes: 34 additions & 0 deletions sql/full_course/multi_tenant_ecommerce/db_tables/tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
USE multi_tenant_ecom_db;

CREATE TABLE Users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
uesr_type VARCHAR(50) CHECK (user_type IN ('customer', 'vendor')) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE Vendors (
id SERIAL PRIMARY KEY,
user_id INT UNIQUE NOT NULL REFERENCES Users(id),
company_name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE Products (
id SERIAL PRIMARY KEY,
vendor_id INT NOT NULL REFERENCES Vendors(id),
name VARCHAR(255) NOT NULL,
description TEXT,
price DECIMAL(10, 2) NOT NULL,
stock_quantity INT NOT NULL CHECK (stock_quantity >= 0),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE Orders(
id SERIAL PRIMARY KEY,
customer_id INT NOT NULL REFERENCES Users(id),
status VARCHAR(50) CHECK (status IN ('pending', 'shipped', 'delivered', 'cancelled')) DEFAULT 'pending',
total_price DECIMAL(10, 2) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

0 comments on commit e120bb2

Please sign in to comment.