Educational Digest

Welcome to Educational Digest – your ultimate destination for coding and technology tutorials! Whether you're a beginner or an experienced programmer, we break down complex concepts into easy-to-follow lessons. Explore programming languages, web development, AI, cybersecurity, and more. Our goal is to make tech learning simple, engaging, and accessible for everyone. Subscribe now and start your journey into the world of technology!


Educational Digest

👉 Which teaching method do you prefer for learning tech concepts?

Vote your style! Do you stick to the classic pen & paper or prefer the modern tablet for learning and teaching? Let’s see which one wins!

#Learning #Teaching #Productivity #TechLearning #StudyTips #YouTubePoll

4 months ago | [YT] | 0

Educational Digest

Using Java stream get the output as count of each character?????

import java.util.*;
import java.util.stream.Collectors;
class Main {
public static void main(String[] args) {
String str="SrijanSingh";//input
//op : count of characters, 2S1R2I1J1A2N1G1H
str = str.toUpperCase();
List<Character> chars = str.chars()
.mapToObj(c -> (char) c)
.collect(Collectors.toList());

Map<Character,Long> freq= chars.stream().collect(Collectors.groupingBy(c -> c,LinkedHashMap::new,Collectors.counting()));

for(Map.Entry<Character,Long> entry: freq.entrySet()){
System.out.print(entry.getValue()+""+entry.getKey());
}
}
}

6 months ago | [YT] | 1

Educational Digest

Given an integer array, find the first and last index of each number that appears in the array.
Input: int[] arr = {1, 5, 1, 2, 8, 2, 8, 8, 8, 1};
Output:
1 -> 0 and 9
5 -> 1 and 1
2 -> 3 and 5
8 -> 4 and 8

import java.util.*;
class Main {
public static void main(String[] args) {
System.out.println("Try programiz.pro");
int[] arr = {1, 5, 1, 2, 8, 2, 8, 8, 8, 1};
Map<Integer,List<Integer>> hm=new HashMap<>();
for(int i=0;i<arr.length;i++){
List<Integer> indexes=new ArrayList<>();
if(!hm.containsKey(arr[i])){
indexes.add(i);
hm.put(arr[i],indexes);
}else{
hm.get(arr[i]).add(i);
}
}
for(Map.Entry<Integer,List<Integer>> entry : hm.entrySet()){
int key=entry.getKey();
List<Integer> positions=entry.getValue();
int firstPos=positions.get(0);
int lastPos=positions.get(positions.size()-1);
System.out.println(key +"->"+ firstPos +" and "+lastPos);
}
}
}

7 months ago | [YT] | 1

Educational Digest

Find the Highest Peak: [1, 2, 1, 3, 5, 6, 4]

public class HighestPeak {
public static void main(String[] args) {
int[] nums = {1, 2, 1, 3, 5, 6, 4};
int highestPeak = Integer.MIN_VALUE;

for (int i = 0; i < nums.length; i++) {
boolean isPeak = false;

if (i == 0 && nums.length > 1 && nums[i] > nums[i + 1]) {
isPeak = true;
} else if (i == nums.length - 1 && nums[i] > nums[i - 1]) {
isPeak = true;
} else if (i > 0 && i < nums.length - 1 && nums[i] > nums[i - 1] && nums[i] > nums[i + 1]) {
isPeak = true;
}

if (isPeak && nums[i] > highestPeak) {
highestPeak = nums[i];
}
}

if (highestPeak != Integer.MIN_VALUE) {
System.out.println("Highest peak: " + highestPeak);
} else {
System.out.println("No peak found.");
}
}
}

8 months ago | [YT] | 1

Educational Digest

Which of the below output is correct?

public static void main(String[] args) {
String[] array = {"abc", "2", "10", "0"};
List<String> list = Arrays.asList(array);
Collections.sort(list);
System.out.println(Arrays.toString(array));
}

8 months ago | [YT] | 0

Educational Digest

Java Coding Problem: Max Average Score from 2D Array (Goldman Sachs Coderpad Interview Question)

You are given a 2D array of strings where each sub-array contains a name and a score (both represented as strings). A person can appear multiple times with different scores.

Your task is to:
Parse the 2D array.
Calculate the average score for each unique person.
Return the name of the person with the highest average score and their average.
String[][] data = {
{"charles", "100"},
{"alice", "80"},
{"charles", "22"},
{"bob", "90"},
{"alice", "70"}
};
Name with max average score: bob
Max average score: 90.0

8 months ago | [YT] | 0

Educational Digest

How to remove all spaces using Java 8 streams?

import java.util.stream.Collectors;

public class RemoveSpaces {
public static void main(String[] args) {
String sentence = "Java 8 Stream API is powerful";

String result = sentence.chars() // get IntStream of characters
.filter(c -> !Character.isWhitespace(c)) // filter out whitespaces
.mapToObj(c -> String.valueOf((char) c)) // convert int to char to String
.collect(Collectors.joining()); // join all into one string

System.out.println(result); // Output: Java8StreamAPIispowerful
}
}

8 months ago | [YT] | 0

Educational Digest

Generate first 10 Fibonacci numbers using stream (CAPGEMINI L1 Interview question)

9 months ago | [YT] | 2

Educational Digest

<Q> Can we have class A injecting dependency of class B and class B having dependency of class A in dependency injection without any issues in spring boot? (Cyclic dependency issue -> BeanCurrentlyInCreationException)

<A> In Spring Boot, having circular dependencies (where Class A depends on Class B, and Class B depends on Class A) can cause issues. However, Spring provides multiple ways to handle such cases.
Spring will detect this circular dependency and throw a BeanCurrentlyInCreationException at runtime.
1. @Lazy : When one dependency can be initialized later
2. Setter Injection : When using constructor injection leads to circular dependency
3. @PostConstruct + @Lazy : When dependencies should be injected after bean creation
4. @Bean in @Configuration : When you need manual control over bean instantiation

9 months ago | [YT] | 0

Educational Digest

What are the benefits of static methods in interface in java?

Static methods in interfaces allow defining utility methods that belong to the interface itself, rather than to instances of implementing classes.

interface MathUtils {
static int square(int x) {
return x * x;
}
}



public class Main {
public static void main(String[] args) {
int result = MathUtils.square(5);
System.out.println(result); // Output: 25
}
}

9 months ago | [YT] | 0