Engineering Blog
11 subscribers
69 photos
76 links
Software Engineer @ EPAM Systems
CS @ Millat Umidi University

Talks about:
πŸ“— OS
πŸ“• Networking
πŸ“™ Backend Engineering
πŸ“˜ RDBMS & NoSQL
πŸ“• DS & ALGO
Download Telegram
Engineering Blog
https://research.google/blog/extra-extra-read-all-about-it-nearly-all-binary-searches-and-mergesorts-are-broken/
This is about bug in binary search implementation in java which is detected 9 years later
😁1
Engineering Blog pinned Β«Recently had an interview for Junior Java Engineer role at Vention Teams. Below you can find sample questions that i was asked during interview: https://telegra.ph/Vention--Interview--Junior-Java-Engineer-07-31Β»
Engineering Blog pinned Β«Hi, recently had a Project Interview at Epam Systems, below you can find the questions: https://telegra.ph/Java--Project-Interview--Epam-Systems-09-11Β»
Spent more then an hour to solve this problem and finally solved it 🎯:)

java  
/*
// Definition for a Node.
class Node {
public int val;
public List<Node> neighbors;
public Node() {
val = 0;
neighbors = new ArrayList<Node>();
}
public Node(int _val) {
val = _val;
neighbors = new ArrayList<Node>();
}
public Node(int _val, ArrayList<Node> _neighbors) {
val = _val;
neighbors = _neighbors;
}
}
*/

class Solution {
public Node cloneGraph(Node node) {

if (node == null) {
return node;
}

Set<Integer> visited = new HashSet<>();
Map<Integer, Node> clones = new HashMap<>();
Queue<Node> q = new LinkedList<>();
q.add(node);

while (!q.isEmpty()) {

Node currNode = q.poll();
int currVal = currNode.val;

if (!visited.contains(currVal)) {

Node nodeClone = clones.getOrDefault(currVal, new Node(currVal));
clones.put(currVal, nodeClone);

for (Node child : currNode.neighbors) {
if (child == null) continue;
Node childClone = clones.getOrDefault(child.val, new Node(child.val));
clones.put(child.val, childClone);
nodeClone.neighbors.add(childClone);
q.add(child);
}

visited.add(currVal);
}
}

return clones.isEmpty() ? node : clones.get(1);
}
}


#leetcode
Solved an interesting leetcode problem today after so many try:


class Solution {

Map<Character, Integer> freq = new HashMap<>();
Map<Character, Integer> count = new HashMap<>();

public int leastInterval(char[] tasks, int n) {

for (char task : tasks) {
freq.put(task, 0);
count.put(task, count.getOrDefault(task, 0) + 1);
}

PriorityQueue<Character> q = new PriorityQueue<>(new CustomOrder());
Set<Character> seen = new HashSet<>();

for (char task : tasks) {
if (seen.contains(task)) {
continue;
}
q.add(task);
seen.add(task);
}


int intervals = 0;
while (!q.isEmpty()) {

boolean hasTask = false;
Queue<Character> tmpQ = new LinkedList<>();
int size = q.size();
for (int i = 0; i < size; i++) {
char task = q.poll();

if (freq.get(task) == 0) {
intervals += 1;
count.put(task, count.get(task) - 1);
if (count.get(task) > 0) {
tmpQ.add(task);
}
decreaseFreq();
freq.put(task, n);
hasTask = true;
break;
}else {
tmpQ.add(task);
}
}

if (!hasTask) {
// cpu idle
decreaseFreq();
intervals += 1;
}
q.addAll(tmpQ);
}

return intervals;
}

private void decreaseFreq() {
for (Map.Entry<Character, Integer> entry : freq.entrySet()) {
char key = entry.getKey();
int occur = entry.getValue();

if (occur > 0) {
freq.put(key, occur - 1);
}
}
}

class CustomOrder implements Comparator<Character> {

@Override
public int compare(Character t1, Character t2) {
if (count.get(t1) > count.get(t2)) {
return -1;
}else if (count.get(t2) > count.get(t1)) {
return 1;
}else {
return 0;
}
}

}
}
Forwarded from MJC School | Uzbekistan
What will be the output of this program:

class Person {
  Person() {
    System.out.print("CP ");
  }

  static {
    System.out.print("SP ");
  }
}

class Manager extends Person {
  Manager() {
    System.out.print("CT ");
  }

  {
    System.out.print("IT ");
  }
}

class Program {
  public static void main(String[] args) {
    Person p1 = new Manager();
  }
}
Forwarded from MJC School | Uzbekistan
Explanation:

Option C is the correct answer.
The static contents are executed when the class is loaded so before the constructors are executed, so the SP will be printed first.  Then the constructor of Person will print CP. Then the Manager class instance code block will print IT before Constructor prints CT.  So, the output is SP CP IT CT. Therefore, option C is correct.
Static content will print only once. So, option D is incorrect.
Other outputs are incorrect as explained above.
The Code compiles fine so, option E is incorrect.

REFERENCE:
http://docs.oracle.com/javase/tutorial/java/IandI/super.html http://docs.oracle.com/javase/tutorial/java/IandI/super.html
Forwarded from MJC School | Uzbekistan
What will be the output of this program:

import java.util.List;

public class MJC {

public static void main(String args[]) {

int factor = 2;
List<Integer> nums = List.of(1, 2, 3, 4, 5);
nums.stream()
.map(num -> num * factor)
.forEach(System.out::print);
factor += 1;
}
}
Forwarded from MJC School | Uzbekistan
Explanation:

Option D is correct.
Lambda expression can only access local variables and parameters of the enclosing block that are final or effectively final. In above code factor does not meet this requirement and compilation fails.

References:
https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#syntax
Forwarded from MJC School | Uzbekistan
πŸ“£ Dive into the world of Java at MJC Open Day #3! Don't miss the exciting opportunity to meet our experienced mentors and community leaders in person, ask questions, and gain valuable insights.

πŸ“… Save the Date: October 11
πŸ•™ Time: 11:00 AM

πŸ“Location: Tashkent, 115A, Makhtumkuli St. (IT Park Tashkent, 1st floor)

βœ”οΈ Secure your spot by registering here.

Join us for engaging discussions on Java Technologies by expert speakers and discover the latest trends in the industry. Celebrate the achievements of our graduating students and get inspired by their success stories during the event.

πŸŽ™ Featured Experts:

Asliddin Eshonkulov - Memory Model in Java.
Javokhir Abdullaev - From Trash to Treasure: How JVM Garbage Collectors Keep Your Code Alive.
Leyla Bakhridinova - Introduction to Cloud. AWS Overview
Ruslan Salikhov - What is MCP server?

Be prepared to ask questions and stand a chance to win exciting gifts for the best ones.

We can't wait to welcome all Java enthusiasts and aspiring developers!