Saturday, 26 August 2023

PreOrder Traversal using iterative approarch(Code in JAVA)


import java.util.*;


public class test {

    static class Node {

        int data;

        Node left;

        Node right;


        public Node(int data) {

            this.data = data;

            this.left = null;

            this.right = null;

        }

    }


    static class BinaryTree {

        static Node buildTree(Scanner scanner, String position, int parentValue) {

            System.out.print("Add " + position + " node for " + parentValue + " (y/n): ");

            String userChoice = scanner.next();


            if (userChoice.equalsIgnoreCase("y")) {

                System.out.print("Enter " + position + " node value: ");

                int nodeValue = scanner.nextInt();

                Node newNode = new Node(nodeValue);


                newNode.left = buildTree(scanner, "left", nodeValue);

                newNode.right = buildTree(scanner, "right", nodeValue);


                return newNode;

            } else {

                return null;

            }

        }

    }

    //levelorder traversal

    public static void levelorder(Node root)

    {

        if(root==null) return;

        Queue<Node> q = new LinkedList<>();

        q.add(root);

        q.add(null);

        while(!q.isEmpty())

        {

            Node currnode = q.remove();

            if(currnode==null) //NULL DENOTES NEW LINE

            {

                System.out.println();

                if(q.isEmpty())

                {

                    break;

                }

                else

                {

                    q.add(null);

                }

            }

            else

            {

                System.out.print(currnode.data+" ");

                if(currnode.left!=null)

                {

                    q.add(currnode.left);

                }

                if(currnode.right!=null)

                {

                    q.add(currnode.right);

                }

            }

        }

    }


    public static ArrayList<Integer> preorderUsingStack(Node root)

    {

        ArrayList<Integer> preorderArrayList = new ArrayList<Integer>();

        if (root==null) return preorderArrayList;

        Stack<Node> st = new Stack<Node>();

        st.push(root);

        while(!st.isEmpty())

        {

            root = st.pop();

            preorderArrayList.add(root.data);

            if(root.right != null)

            {

                st.push(root.right);

            }

            if(root.left != null)

            {

                st.push(root.left);

            }


        }

        return preorderArrayList;

    }


    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        BinaryTree bt = new BinaryTree();

        

        System.out.print("Enter root node value: ");

        int rootValue = scanner.nextInt();

        Node root = new Node(rootValue);


        root.left = bt.buildTree(scanner, "left", rootValue);

        root.right = bt.buildTree(scanner, "right", rootValue);


        System.out.println("Tree construction complete.");

        levelorder(root);

        System.out.println(preorderUsingStack(root));

        scanner.close();

    }

}



  

Friday, 25 August 2023

LevelOrder Traversal in Binary Tree (code in JAVA)



import java.util.LinkedList;

import java.util.Queue;

import java.util.Scanner;


public class test {

    static class Node {

        int data;

        Node left;

        Node right;


        public Node(int data) {

            this.data = data;

            this.left = null;

            this.right = null;

        }

    }


    static class BinaryTree {

        static Node buildTree(Scanner scanner, String position, int parentValue) {

            System.out.print("Add " + position + " node for " + parentValue + " (y/n): ");

            String userChoice = scanner.next();


            if (userChoice.equalsIgnoreCase("y")) {

                System.out.print("Enter " + position + " node value: ");

                int nodeValue = scanner.nextInt();

                Node newNode = new Node(nodeValue);


                newNode.left = buildTree(scanner, "left", nodeValue);

                newNode.right = buildTree(scanner, "right", nodeValue);


                return newNode;

            } else {

                return null;

            }

        }

    }

    //levelorder traversal

    public static void levelorder(Node root)

    {

        if(root==null) return;

        Queue<Node> q = new LinkedList<>();

        q.add(root);

        q.add(null);

        while(!q.isEmpty())

        {

            Node currnode = q.remove();

            if(currnode==null)

            {

                System.out.println();

                if(q.isEmpty())

                {

                    break;

                }

                else

                {

                    q.add(null);

                }

            }

            else

            {

                System.out.print(currnode.data+" ");

                if(currnode.left!=null)

                {

                    q.add(currnode.left);

                }

                if(currnode.right!=null)

                {

                    q.add(currnode.right);

                }

            }

        }

    }


    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        BinaryTree bt = new BinaryTree();

        

        System.out.print("Enter root node value: ");

        int rootValue = scanner.nextInt();

        Node root = new Node(rootValue);


        root.left = bt.buildTree(scanner, "left", rootValue);

        root.right = bt.buildTree(scanner, "right", rootValue);


        System.out.println("Tree construction complete.");

        levelorder(root);

        scanner.close();

    }

}



  

 BinaryTree Data Structure implementation in JAVA: ( User Input Method)


import java.util.Scanner;

public class test {
    static class Node {
        int data;
        Node left;
        Node right;

        public Node(int data) {
            this.data = data;
            this.left = null;
            this.right = null;
        }
    }

    static class BinaryTree {
        static Node buildTree(Scanner scanner, String position, int parentValue) {
            System.out.print("Add " + position + " node for " + parentValue + " (y/n): ");
            String userChoice = scanner.next();

            if (userChoice.equalsIgnoreCase("y")) {
                System.out.print("Enter " + position + " node value: ");
                int nodeValue = scanner.nextInt();
                Node newNode = new Node(nodeValue);

                newNode.left = buildTree(scanner, "left", nodeValue);
                newNode.right = buildTree(scanner, "right", nodeValue);

                return newNode;
            } else {
                return null;
            }
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BinaryTree bt = new BinaryTree();
        
        System.out.print("Enter root node value: ");
        int rootValue = scanner.nextInt();
        Node root = new Node(rootValue);

        root.left = bt.buildTree(scanner, "left", rootValue);
        root.right = bt.buildTree(scanner, "right", rootValue);

        System.out.println("Tree construction complete.");
        scanner.close();
    }
}


  

 BinaryTree Data Structure implementation in JAVA: (Hard Coding Method)


public class test {

    static class Node {   

        int data;

        Node left;

        Node right;


        public Node(int data) {

            this.data = data;

            this.left = null;  // even if we do not explicitly specify them as null  then also it is by default                                            //set up as null in JAVA but it is always a good practise to assign them as          this.right = null;                                    //null

         

        }

    }

 

    static class BinaryTree {

        static Node buildTree(int rootValue) {

            if (rootValue == -1) return null;

            Node newNode = new Node(rootValue); // Now you can instantiate Node directly

            //newNode.left = null;

            //newNode.right = null;

            return newNode;

        }

    }


    public static void main(String[] args) {

        // You can create instances of Node and BinaryTree here as needed

        BinaryTree bt = new BinaryTree();

//For the sake of understanding we are doing hardcoding now. We'll see user input coding also in next article

        Node root = BinaryTree.buildTree(10); //Node root = bt.buildTree(10);

        root.left = new Node(6); 

        root.right= new Node(12);

        root.left.left = new Node(5);

        root.right.right = new Node(7);

        System.out.println(root.data);

        System.out.println(root.left.data+" "+root.right.data);

        System.out.println(root.left.left.data+" "+root.right.right.data);

         /* Our Tree is something like below:

                10
                /\

            6       12

            /            \

        5                    7

*/

    }

}

/*

Question: when we are removing both newnode.right and newnode.left = null and also this,left=null and this.right=null then also we are getting root.left value as null and no error is coming why?

The reason you're not seeing any errors or changes in the behavior of your program when you remove both newnode.left = null; and newnode.right = null; from the buildTree method and also remove this.left = null; and this.right = null; from the Node constructor is because Java automatically initializes object fields to default values when an object is created.

In Java, when you create a new object (instance of a class), all instance variables (fields) are automatically initialized to default values. For numeric types like int, the default value is 0, and for object types, including reference types like Node, the default value is null.

In your Node class constructor, you are manually setting left and right to null, but if you don't provide any initialization for these fields, Java will still initialize them to null by default when you create a new Node object.

Similarly, in the buildTree method, even if you remove the lines that explicitly set newnode.left and newnode.right to null, Java will automatically set them to null when the Node object is created.

That's why you're not observing any difference in behavior or errors when you remove these lines. Java's default behavior takes care of it for you.

 */

Thursday, 24 August 2023

 Codeforces Round 894 Div 3 Solution:

Problem Statement Link -->   Problem - A - Codeforces

Solution in JAVA:


import java.util.*;


public class test {


    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);


        int testCases = scanner.nextInt();


        for (int testCase = 0; testCase < testCases; testCase++) {


            int numRows = scanner.nextInt();

            int numCols = scanner.nextInt();


            List<String> carpetRows = new ArrayList<>();


            for (int i = 0; i < numRows; i++) {

                carpetRows.add(scanner.next());

            }


            int requiredColumns = 4;

            String target = "vika";

            int targetIndex = 0;

            int selectedColumns = 0;


            for (int col = 0; col < numCols; col++) {


                boolean foundColumn = false;


                for (int row = 0; row < numRows; row++) {


                    String rowContent = carpetRows.get(row);

                    char currentChar = rowContent.charAt(col);


                    if (currentChar == target.charAt(targetIndex)) {

                        targetIndex++;

                        foundColumn = true;

                        break;

                    }

                }


                if (foundColumn) {

                    selectedColumns++;

                    if (selectedColumns == requiredColumns) {

                        break;

                    }

                }

            }


            if (selectedColumns == requiredColumns) {

                System.out.println("YES");

            } else {

                System.out.println("NO");

            }

        }


        scanner.close();

    }

}


Wednesday, 23 August 2023

Codeforces Round 640 Div 4 Solution:

Problem Statement Link -->  Status - Codeforces

Solution in JAVA:


import java.util.*;


public class test {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        

        for (int i = 0; i < t; i++) {

            int num = sc.nextInt();

            List<Integer> terms = new ArrayList<>();

            

            int multiplier = 1;

            while (num > 0) {

                int digit = num % 10;

                if (digit > 0) {

                    terms.add(digit * multiplier);

                }

                num /= 10;

                multiplier *= 10;

            }

            

            System.out.println(terms.size());

            for (int term : terms) {

                System.out.print(term + " ");

            }

            System.out.println();

        }

        

        sc.close();

    }

}


Monday, 21 August 2023

Codeforces Round 107 Div 2 Solution:

Problem Statement Link --> Problem - 151A - Codeforces

Solution in JAVA:


import java.util.*;


public class test {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n, k, l, c, d, p, nl, np;

        n = sc.nextInt();

        k = sc.nextInt();

        l = sc.nextInt();

        c = sc.nextInt();

        d = sc.nextInt();

        p = sc.nextInt();

        nl = sc.nextInt();

        np = sc.nextInt();

        int num_of_toasts = Math.min(Math.min((k * l) / (n * nl), (c * d) / n), p / (n * np));

        System.out.println(num_of_toasts);

        sc.close();

    }

}


Codeforces Round 161 Div 2 Solution in Java

Problem Statement Link --> Problem - 263A - Codeforces

Solution in JAVA:

import java.util.*;

public class test {

public static void main(String[] args) {

    int arr[][] = new int[6][6] ;

    int r=0;int c=0;

    Scanner sc = new Scanner(System.in);

    for (int i = 1; i < 6; i++) {

        for (int j = 1; j < 6; j++) {

           arr[i][j] = sc.nextInt();

           if(arr[i][j] == 1)

           {

            r = Math.abs(3-i);

            c = Math.abs(3-j);

           }

        }

    }

    System.out.println(r+c);

    sc.close();

  }   

}

Tuesday, 15 August 2023

Video Solution for Codeforces Round 893 DIV 2 - Problem A in #JAVA 



Hello fellow programmers,

For those of you who participated in Codeforces Round 893 DIV 2 and were working on Problem A, here is the solution in JAVA



Solution in JAVA 

import java.util.*;

public class test {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();   //for total number of test cases
        for (int i = 0; i < t; i++) {
            int a, b, c;   
            a = sc.nextInt();
            b = sc.nextInt();
            c = sc.nextInt();
            int qwerty = c/2;  
            a = a + c - qwerty;
            b = b + qwerty;
            if(a>b)
            {
                System.out.println("First"); //Anna will win
            }
            else
            {
                System.out.println("Second"); //else Katie
            }
             
    }
    sc.close();
  }
}

Saturday, 12 August 2023

Video Solution for Codeforces Round 892 DIV 2 - Problem A in #JAVA 


Hello fellow programmers,

For those of you who participated in Codeforces Round 892 DIV 2 and were working on Problem A, here is the solution in JAVA


import java.util.*;

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt(); //FOR NUMBER OF TEST CASES

        for (int i = 0; i < t; i++) {
            int n = sc.nextInt(); // length of the array a
            int[] a = new int[n];
            
            // Input the array a
            for (int j = 0; j < n; j++) {
                a[j] = sc.nextInt();
            }
            
            Arrays.sort(a); //SORT THE ARRAY SO THAT IT CAN BE DIVIDED INTO b and c
            boolean flag=false; //TAKING variable flag for output purpose
            for(int k=0 ;  k<n-1 && !flag;k++) // and flag is important 
            {
                if(a[k] != a[k+1])
                {
                    flag=true;
                
             
            System.out.println(k+1 + " " + (n-k-1)); 
            for(int m=0;m<=k;m++)
            {
                System.out.print(a[m]+" ");
            }
            System.out.println();
            for(int p=k+1;p<n;p++)
            {
                System.out.print(a[p]+" ");
            }
                 }
                   
            } //loop is over here
            if(!flag) //otherwise -1 according to the question
                 {
                    System.out.println(-1);
                 }
        }
        sc.close();
    }
}

 
 
 

Friday, 14 July 2023

Hello World!! 

Data Visualization Project: Census of India 2011 - Population of Religious Groups in a State

Project's Link - https://amanraj1212.pythonanywhere.com

My Portfolio website's Link - https://amanraj-website.netlify.app

This is a full stack project from development to deployment.


I have created an intriguing data visualization project focused on the Census of India 2011. This project aims to provide insights into the population distribution of different religious groups across a particular state. By utilizing the data from the Census, I have implemented a bar graph visualization that effectively represents the population numbers for each religious group.


The visualization allows users to explore and compare the population of various religious groups within the selected state. By presenting the data in a bar graph format, it becomes easy to comprehend the relative sizes and proportions of each religious group. This visualization enables users to identify trends, patterns, and disparities in the population distribution, facilitating a better understanding of the demographics within the state.


Through this project, I have successfully combined data analysis, visualization techniques, and web development skills to create an informative and interactive tool. It provides a visual representation of the religious diversity within the chosen state based on the Census data from 2011.


Overall, my data visualization project offers a valuable resource for individuals interested in exploring the population distribution of religious groups in a specific state. It highlights the power of data visualization in conveying complex information effectively and engagingly.


Feel free to visit my website and explore my data visualization project further. It's a great opportunity to gain insights into the Census of India 2011 and appreciate the power of data visualization in understanding demographic trends.

Sunday, 11 June 2023

Here is a Java practice problem taken from HackerRank that tests your knowledge of strings. The problem involves arranging strings in lexicographical order and capitalizing the first letter of each word. It's a great exercise for revision and practice. Here's the problem description and a sample solution:

Problem statement:

Given two strings of lowercase English letters, and B, perform the following operation:

  1. Sum of length of and B.
  2. Determine if is lexicographically larger than B(i.e.: comes after A in dictionary?).
  3. Capitalize the first letter of and B and print them on a single line, separated by a space.

Input Format

The first line contains a string A. The second line contains another string B. The strings are comprised of only lowercase English letters.

Output Format

There are three lines of output:
For the first line, sum the lengths of and B.
For the second line, write Yes if is lexicographically greater than otherwise print No instead.
For the third line, capitalize the first letter in both A and and print them on a single line, separated by a space.

Sample Input
 hello
 java
Sample Input
 9
 No
 Hello Java
Explanation

String is “hello” and is “java”. has a length of 5, and has a length of 4; the sum of their lengths is 9.
When sorted alphabetically/lexicographically, “hello” precedes “java”; therefore, is not greater than and the answer is No. When you capitalize the first letter of both and and then print them separated by a space, you get “Hello Java”.

// My solution:

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
         
        Scanner scanner = new Scanner(System.in);
        String A = scanner.nextLine();
        String B = scanner.nextLine();
        scanner.close();
        String lCaseA= A.toLowerCase();
        String lCaseB=B.toLowerCase();
        System.out.println(lCaseA.length()+lCaseB.length());
        String flag="Yes";
        int min=lCaseB.length();
        if(lCaseA.length()<=lCaseB.length()) min=lCaseA.length();
        //System.out.println(max);
        int i=0;
        while(i<min)
        {
           if((int)lCaseA.charAt(i)<(int)lCaseB.charAt(i))
           {
              flag="No";
              break;
           }
           else if((int)lCaseA.charAt(i)==(int)lCaseB.charAt(i))
           {
            i++;   
            flag="No";
            continue;
           }
           else
           {
            break;
           }
         
        }
      //System.out.println(lCaseA);
      //System.out.println(lCaseB);
      System.out.println(flag);   
      
      String ucase=" ";
       Scanner scaner=new Scanner(lCaseA);
       while(scaner.hasNext())
       {
        String word=scaner.next();
        ucase+=Character.toUpperCase(word.charAt(0))+word.substring(1)+" ";

       }
       System.out.print(ucase.trim()+" ");
       scaner.close();
       
       String ucase1=" ";
       Scanner scaner1=new Scanner(lCaseB);
       while(scaner1.hasNext())
       {
        String word1=scaner1.next();
        ucase1+=Character.toUpperCase(word1.charAt(0))+word1.substring(1)+" ";

       }
       System.out.println(ucase1.trim());
       scaner1.close();
    }
}

// program ends

While the provided solution uses two separate while loops for simplicity,
it is worth mentioning that a dedicated function can be created to encapsulate
the logic of capitalizing the first letter of a word. This approach can make the
code more modular and readable. (For the sake of better understanding I showed
with two separate loops)
By practicing this problem, you will gain a deeper understanding of string
manipulation and improve your ability to solve similar challenges efficiently.
Mastery of these concepts will prove valuable in real-world scenarios where
string handling plays a crucial role. Remember to consider edge cases, such as handling empty strings or strings with
leading/trailing spaces(trim()). Understanding these nuances will enhance the robustness
of your solution and make it applicable in various scenarios. Conclusion: This Java practice problem focusing on arranging strings in lexicographical
order and capitalizing the first letter of each word provides an excellent
opportunity to revise and strengthen your skills in string manipulation.
By understanding and implementing the solution, you will enhance your ability to
work with strings effectively and tackle similar challenges with confidence.
Practice this problem and continue exploring more string-related problems to
expand your knowledge and become proficient in different programming logic.

Sunday, 7 May 2023

Greetings, readers! Today's blog post is going to be a bit different than what I usually write about. Instead of discussing technical topics or sharing my latest projects, I want to talk about something that is often overlooked but can have a significant impact on our personal and professional lives: IMPOSTER SYNDROME. Despite being a common experience, imposter syndrome is not often talked about openly in our ongoing professional journey. Yet, it is a pervasive feeling that many people face at some point in their lives. If you haven't experienced it yet, chances are you will encounter it in the near future. In this blog post, I want to shed light on what imposter syndrome is, why it is so common, and how we can overcome it to continue learning and growing. 


Imposter syndrome is a psychological phenomenon that affects many people, especially those who are high achievers or who are pursuing advanced degrees or careers. It is characterized by feelings of self-doubt and insecurity, and a persistent belief that one's successes are due to luck or external factors rather than one's own abilities.

If you are struggling with imposter syndrome, it can be easy to feel discouraged and give up on your goals. However, it is important to remember that imposter syndrome is a common experience, and that it is possible to overcome it and continue learning and growing.

One of the first steps in overcoming imposter syndrome is to recognize that it is a normal and common experience. Many successful people, including scientists, writers, and entrepreneurs, have struggled with feelings of inadequacy and self-doubt at some point in their careers. By acknowledging that imposter syndrome is a common experience, you can start to let go of some of the shame and stigma that may be associated with it.

Another key to overcoming imposter syndrome is to focus on your strengths and accomplishments. It can be easy to discount or dismiss your achievements when you are feeling self-doubt, but it is important to take time to acknowledge and celebrate your successes. Make a list of your accomplishments, no matter how small, and reflect on the hard work and dedication that went into achieving them.

It can also be helpful to seek out support from others. Talk to friends, family members, or colleagues who can offer encouragement and support. Consider joining a support group or seeking out a mentor who can provide guidance and advice as you navigate your career or academic path.

Finally, remember that learning and growth are ongoing processes. No one is an expert in everything, and it is normal to encounter challenges and setbacks along the way. By viewing these challenges as opportunities for growth and learning, you can overcome imposter syndrome and continue to pursue your goals with confidence and determination.

In summary, imposter syndrome is a common experience that can leave us feeling discouraged and insecure. However, by acknowledging our achievements, seeking support from others, and viewing challenges as opportunities for growth, we can overcome imposter syndrome and continue learning and growing. Remember, you are capable of achieving great things, and you deserve to pursue your dreams with confidence and determination.

Friday, 14 April 2023

                                   Backend Developers Paradise --> DTL (Django Template Language)

If you're a full stack web developer who's been around the block when it comes to frontend and backend development, you may be feeling a pull towards the backend side of things. However, you may not be too keen on making the shift to JavaScript for fetching APIs. Fear not! There's a powerful tool at your disposal that may just tickle your fancy: the Django template language.

Django is a high-level Python web framework that takes care of a lot of the heavy lifting when it comes to building web applications. It's been around for quite some time and has built up a solid reputation in the development community. One of the key features of Django is its templating system, which allows you to create dynamic web pages using a combination of HTML, CSS, and Python.

The Django template language is a powerful tool that allows you to create complex, dynamic web pages without having to rely on a lot of JavaScript. With its easy-to-use syntax and powerful features, the Django template language is an excellent choice for developers who want to focus on the backend but still want to create stunning, interactive web pages.

So if you're looking to level up your backend game and want to explore a powerful and flexible tool for creating dynamic web pages, then look no further than the Django template language. Whether you're building a small-scale web application or a large-scale enterprise project, Django has got you covered.

Django Template Language (DTL) is a template language that is an integral part of the Django web framework. DTL provides developers with a powerful and flexible way to create dynamic web pages. With its rich set of features, DTL is an excellent choice for developers who want to create high-quality web applications quickly and efficiently.

One of the key advantages of using DTL is that it is easy to learn and use. The syntax of DTL is simple and straightforward, making it accessible to developers of all skill levels. The template tags and filters provided by DTL make it easy to manipulate data and create dynamic content.

Another advantage of using DTL is its modular design. DTL allows you to create modular templates that can be reused across multiple pages. This makes it easy to maintain consistency across your website and reduces the amount of code you need to write.

DTL also provides built-in security features that prevent common web vulnerabilities such as cross-site scripting (XSS) attacks. It also provides protection against SQL injection attacks by automatically escaping any data that is entered into the templates. This makes DTL a popular choice among developers who value security.

DTL is also highly customizable, allowing developers to create their own template tags and filters. This enables them to extend the functionality of DTL to meet their specific needs, which is a valuable feature for developers working on complex projects.

However, there are some limitations to using DTL. It is primarily a template language and does not support complex logic or control structures. While you can use if/else statements and loops, they are limited in their functionality. Additionally, DTL is not designed to work with dynamic content such as real-time updates or live streaming.

Despite these limitations, DTL remains a powerful tool that offers many benefits to web developers. Its ease of use, security, and performance make it a great choice for creating dynamic and engaging web pages that are easy to maintain and customize. For developers looking to create powerful and scalable web applications, DTL is a valuable tool that should not be overlooked.

In conclusion, Django Template Language is a powerful template language that provides a wide range of features and capabilities for web developers. While it has some limitations, these are outweighed by its many advantages, including its ease of use, security, and performance. Whether you are a beginner or an experienced web developer, DTL is a great choice for creating dynamic and engaging web pages that are easy to maintain and customize.

You can start learning about Django and DTL from its official documentation and from the Youtube channel Geeky Shows (It is long but rock-solid playlist available on youtube)

Sunday, 4 December 2022

Learning more will never be a disadvantage

Hello world, 🙏

Every novice in programming get stuck with a basic problem WHICH LANGUAGE DO THEY PREFER? They are advised by the most to not follow C language. They should directly jump into some language supporting OOPs. Well, I disagree here as C language gives you an encapsulated feel of MEMORY architecture which is paramount topic in CS . Also, learning more will never be a disadvantage. It will only act as a boon.

You can read an article by Mario Galindo Queralt related to this topic below which I found on Quora. I am attaching the link of the same below.

Question:  

Why do universities teach C and C++, though they are regarded as the most difficult languages and there are better alternatives? C and C++ aren’t expanding and will be dead in 30 years, but Stanford, Harvard and U Mich use C++ as a primary language.

 

Answer:

You are totally uninformed. C++ is expanding a lot. The latest version is C++17, next year the C++20 version is being issued, the committee is working hard on C++23 and C++26 is scheduled.

You believe that C and C++ will be dead in 30 years. That belief is based entirely on unsubstantiated speculation. If you don't know anything about the present, less can you know about the future.

In spite of that, 30 years of prognosis in the future is a great deal of time for CS. Therefore, it is feasible to consider that everything, yes EVERYTHING, what exists today in CS will somehow be dead in 30 years. Based on this presumption, should you, and everyone, stop studying absolutely everything today?

Stanford and Harvard are among the most important engineering universities in the world. You must trust their teachers when they choose C and C++ as their primary computer languages. Believe me, they know much more than you.

Therefore, if something is difficult for you, I recommend that you study it more, instead of looking for false arguments to modify what is taught in the university. Do not pretend to teach your teachers, it is the other way around, they are the ones who teach and you who learn.

Regards.

Link to read above on Quora:  Why do universities teach C and C++, though they are regarded as the most difficult languages and there are better alternatives? C and C++ aren’t expanding and will be dead in 30 years, but Stanford, Harvard and U Mich use C++ as a primary language. - Quora

Good thoughtful question on Binary search on answers

Problem link:  https://leetcode.com/problems/maximize-score-of-numbers-in-ranges/description/ Solution: //import java.util.Arrays; class So...