{"id":10880,"date":"2024-06-21T11:42:24","date_gmt":"2024-06-21T11:42:24","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=10880"},"modified":"2024-06-21T11:42:24","modified_gmt":"2024-06-21T11:42:24","slug":"infosys-coding-questions","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/infosys-coding-questions\/","title":{"rendered":"Top 10 Infosys Coding Questions and Answers 2024"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><p><strong>Table of Contents<\/strong><\/p><nav><ul><li class=\"\"><a href=\"#infosys-coding-and-pseudo-code-questions-2024\">Infosys Coding And Pseudo-code Questions 2024<\/a><\/li><li class=\"\"><a href=\"#infosys-pseudocode-questions-2024\">Infosys Pseudocode Questions 2024<\/a><\/li><li class=\"\"><a href=\"#10-infosys-pseudo-code-questions-with-answers-2024\">10 Infosys Pseudo-code Questions With Answers 2024<\/a><\/li><li class=\"\"><a href=\"#13-infosys-coding-questions-and-answers-2024\">13 Infosys Coding Questions and Answers 2024<\/a><\/li><li class=\"\"><a href=\"#10-infosys-coding-questions-for-specialist-programmer-2024\">10 Infosys Coding Questions For Specialist Programmer 2024<\/a><\/li><li class=\"\"><a href=\"#important-links-infosys-coding-questions\">Important Links- Infosys Coding Questions<\/a><\/li><li class=\"\"><a href=\"#infosys-coding-questions-fa-qs\">Infosys Coding Questions- FAQs<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"infosys-coding-and-pseudo-code-questions-2024\">Infosys Coding And Pseudo-code Questions 2024<\/h2>\n\n\n\n<p><strong>Practice the top 10 Infosys Coding and Pseudo-code Questions uploaded to crack the Infosys exam on the first attempt.<\/strong> These coding questions will evaluate a candidate&#8217;s problem-solving abilities, logical thinking, and proficiency in programming languages. The questions range from simple data structure and algorithm problems to more complex ones involving real-world scenarios. This blog focuses on the Top 13 Infosys Coding Questions and Answers for the examination and 10 Coding Questions for specialist programmers in 2024. We have also uploaded Infosys Pseudocode questions with answers here.<\/p>\n\n\n\n<p>Top IT firms like Infosys require coding skills and problem-solving skills for their hiring process for 2024. These skills are mandatory for the candidates applying for the job in Infosys and are used to evaluate during the Infosys interview and online test. The Pseudocode round is one of the important rounds in the Infosys coding questions in 2024. Through this Pseudocode round, they will analyze the candidate&#8217;s ability to write the algorithmic solutions with the simplified code.<\/p>\n\n\n\n<p>Infosys coding questions often test a candidate&#8217;s understanding of concepts like arrays, strings, linked lists, trees, recursion, and dynamic programming. Solving these questions efficiently and effectively is crucial for aspiring candidates to showcase their coding skills and stand out in the competitive hiring process.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"infosys-pseudocode-questions-2024\">Infosys Pseudocode Questions 2024<\/h2>\n\n\n\n<p>Pseudo-code in data science, is a step-by-step description of the computer algorithm. In short, It is the high-level, language-agnostic representation of the algorithm. It indicates how to write down the algorithm&#8217;s steps in a language-agnostic manner.<\/p>\n\n\n\n<p>Furthermore, it is useful in the early stages of software development and aids the programmers to organize and structure the programs before writing the actual code. This will also help developers focus on the program&#8217;s logic and flow. Pseudo-code will use programming language such as loops, conditionals and variables, and English words and phrases.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Infosys Pseudocode Question <\/strong><\/td><td><strong>Details<\/strong><\/td><\/tr><tr><td>Duration <\/td><td>10 minutes <\/td><\/tr><tr><td>Number of Questions<\/td><td>5 Question<\/td><\/tr><tr><td>Negative Marking <\/td><td>No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The Infosys Pseudo-code round has 5 questions, to be completed in 10 minutes. Pseudo-code is considered the representation of the algorithm code in Java, C, and C++. The difficulty level of the Infosys Pseudo-code Questions is moderate-high. Pseudo-code refers to the algorithm that is displayed in the coding format.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Infosys Pseudo-Code Topics<\/strong><\/td><td><strong>Questions<\/strong><\/td><td><strong>Difficulty level<\/strong><\/td><\/tr><tr><td>OOPS <\/td><td>2<\/td><td>Medium <\/td><\/tr><tr><td>C<\/td><td>1<\/td><td>Medium<\/td><\/tr><tr><td>C++<\/td><td>2<\/td><td>Medium<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Check out the Top 10 Infosys Pseudo-code questions with answers in 2024. Solve these pseudo-code questions and crack the Infosys interview and exam.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"10-infosys-pseudo-code-questions-with-answers-2024\"><strong>10 Infosys Pseudo-code Questions With Answers<\/strong> 2024<\/h2>\n\n\n\n<p> The top 10  Infosys Pseudo-code questions are added here for your reference. Candidates preparing for the Infosys interview can understand and practice the Infosys Pseudo-code questions provided below.<\/p>\n\n\n\n<p><strong>1. What will be the output of the pseudocode given here?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Main {\n    public static void main(String&#91;] args) {\n        String names&#91;] = new String&#91;5];\n        for(int x = 0; x &lt; args.length &amp;&amp; x &lt; names.length; x++) {\n            names&#91;x] = args&#91;x];\n        }\n        if (args.length &gt;= 3) {\n            System.out.println(names&#91;2]);\n        } else {\n            System.out.println(\"Not enough arguments provided\");\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>Ans<\/strong>.<\/p>\n\n\n\n<p><strong>Scenario 1: Exactly 5 Arguments<\/strong><\/p>\n\n\n\n<p>Command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java Main one two three four five<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>three<\/code><\/pre>\n\n\n\n<p><strong>Scenario 2: Fewer Than 3 Arguments<\/strong><\/p>\n\n\n\n<p>Command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java Main one two<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Not enough arguments provided<\/code><\/pre>\n\n\n\n<p><strong>Scenario 3: More Than 5 Arguments<\/strong><\/p>\n\n\n\n<p>Command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java Main one two three four five six<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>three<\/code><\/pre>\n\n\n\n<p><strong>Scenario 4: Exactly 3 Arguments<\/strong><\/p>\n\n\n\n<p>Command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java Main one two three<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>three<\/code><\/pre>\n\n\n\n<p><strong>Scenario 5: No Arguments<\/strong><\/p>\n\n\n\n<p>Command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java Main<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Not enough arguments provided<\/code><\/pre>\n\n\n\n<p>These outputs correspond to the improved version of the program which includes a check to ensure there are at least 3 arguments before accessing <code>names[2]<\/code>.<\/p>\n\n\n\n<p><strong>2. What will be the output of the  Pseudo Code provided below?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\nint main()\n{\n    float i;\n    i = 1;\n    printf(\"%f\", i);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>Ans<\/strong>. Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1.000000<\/code><\/pre>\n\n\n\n<p><strong>3. What will be the output of the pseudocode given here?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\nint main()\n{\n    int num = 987;\n    int rem;\n    while(num!=0)\n    {\n        rem = num % 4;\n        num = num \/ 10;\n    }\n    printf(\"%d\",rem);\n}<\/code><\/pre>\n\n\n\n<p><strong>Ans<\/strong>. Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n<\/code><\/pre>\n\n\n\n<p><strong>4. What will be the output of the pseudo-code provided here?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;stdio.h&gt;\nint main(){\n    float x = 0.0;\n    long int y = 10;\n    printf(\"%d\", sizeof(x) == sizeof(x+y));\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>Ans<\/strong>. Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1<\/code><\/pre>\n\n\n\n<p><strong>5. What will be the output of the pseudocode<\/strong> <strong>below<\/strong>?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;stdio.h&gt;\nint main()\n{\nint go = 5.0, num = 1*10;\ndo \n{\nnum \/= go;\n} while(go--);\nprintf (\"%d\\n\", num);\nreturn 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>Ans<\/strong>. Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0<\/code><\/pre>\n\n\n\n<p><strong>6. What is the output of the program given below?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;stdio.h&gt;\nint main()\n{\n    int any = ' ' * 10;\n    printf(\"%d\", any);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>Ans<\/strong>. Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>320<\/code><\/pre>\n\n\n\n<p><strong>7. Write the output for the given program.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;stdio.h&gt;\nint main(){\n    float x = 0.0;\n    long int y = 10;\n    printf(\"%d\", sizeof(y) == sizeof(x+y));\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>Ans. <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0<\/code><\/pre>\n\n\n\n<p><strong>8. What is the output of the following program?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;stdio.h&gt;\nint main() \n{\n    typedef int num;\n    num bunk = 0.00;    \n    printf(\"%d\", bunk);\n    return 0;\n    \n}<\/code><\/pre>\n\n\n\n<p><strong>Ans<\/strong>. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0<\/code><\/pre>\n\n\n\n<p><strong>9. What is the output?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;stdio.h&gt;\nint main()\n{\n    int a = 100;\n    printf(\"%0 %x\", a);\n}<\/code><\/pre>\n\n\n\n<p><strong>Ans<\/strong>. Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>100 64 <\/code><\/pre>\n\n\n\n<p><code>%d<\/code>: <code>100<\/code> is printed in decimal format.<code>%x<\/code>: <code>100<\/code> is printed in hexadecimal format. In hexadecimal, <code>100<\/code> is represented as <code>64<\/code>.<\/p>\n\n\n\n<p><strong>10. What is the output?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;stdio.h&gt;\nint main()\n{\n    for (int x = 10; x &gt;= 0; x--) {\n        int z = x &amp; (x &gt;&gt; 1);\n        if (z)\n            printf(\"%d \", x);\n     }\n    \n}<\/code><\/pre>\n\n\n\n<p><strong>Ans<\/strong>.<\/p>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10 9 8 7 6 5 4 3 2 1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"13-infosys-coding-questions-and-answers-2024\">13 Infosys Coding Questions and Answers 2024<\/h2>\n\n\n\n<p>In Infosys Exam, they have 3 Infosys coding questions, to be completed in 3 hours. So, candidates should practice the Infosys coding questions and answers for the Infosys Exam. Check out the table below to learn more about the difficulty level of the Infosys Coding Question.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Infosys Coding Questions<\/strong><\/td><td><strong>Infosys Coding Topics<\/strong><\/td><td><strong>Difficulty Level<\/strong><\/td><\/tr><tr><td>1<\/td><td>Aptitude, Algorithm and Data Structures.<\/td><td>Easy <\/td><\/tr><tr><td>2<\/td><td>Greedy Algorithm<\/td><td>Medium<\/td><\/tr><tr><td>3<\/td><td>&nbsp;Dynamic Programming<\/td><td>Hard Level<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Applicants of the Infosys examination can refer to the coding questions and answers added here. Check the Infosys coding questions and answers, and improve your coding skills.<\/p>\n\n\n\n<p>1. <strong>Write a program to arrange the given number to form the biggest number.<\/strong><\/p>\n\n\n\n<p><strong>Ans. <\/strong><\/p>\n\n\n\n<p><strong>Python <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from functools import cmp_to_key\n\ndef compare(x, y):\n    # Compare combined numbers to determine order\n    if x + y &gt; y + x:\n        return -1\n    elif x + y &lt; y + x:\n        return 1\n    else:\n        return 0\n\ndef largest_number(nums):\n    # Convert numbers to strings for easy concatenation\n    str_nums = &#91;str(num) for num in nums]\n    # Sort numbers using custom comparator\n    str_nums.sort(key=cmp_to_key(compare))\n    # Join sorted numbers to form the largest number\n    largest_num = ''.join(str_nums)\n    # Edge case for leading zeros\n    return largest_num if largest_num&#91;0] != '0' else '0'\n\n# Example usage\nnumbers = &#91;3, 30, 34, 5, 9]\nprint(\"The largest number is:\", largest_number(numbers))<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The largest number is: 9534330<\/code><\/pre>\n\n\n\n<p><strong>Java <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Arrays;\nimport java.util.Comparator;\n\npublic class LargestNumber {\n\n    \/\/ Custom comparator to decide the order based on concatenation\n    private static class NumberComparator implements Comparator&lt;String&gt; {\n        @Override\n        public int compare(String x, String y) {\n            String order1 = x + y;\n            String order2 = y + x;\n            return order2.compareTo(order1); \/\/ reverse order for descending\n        }\n    }\n\n    public static String largestNumber(int&#91;] nums) {\n        \/\/ Convert int array to String array\n        String&#91;] strNums = Arrays.stream(nums)\n                .mapToObj(String::valueOf)\n                .toArray(String&#91;]::new);\n\n        \/\/ Sort array using custom comparator\n        Arrays.sort(strNums, new NumberComparator());\n\n        \/\/ Edge case: Check if the largest number is 0\n        if (strNums&#91;0].equals(\"0\")) {\n            return \"0\";\n        }\n\n        \/\/ Join sorted array to form the largest number\n        StringBuilder largestNum = new StringBuilder();\n        for (String num : strNums) {\n            largestNum.append(num);\n        }\n\n        return largestNum.toString();\n    }\n\n    public static void main(String&#91;] args) {\n        int&#91;] numbers = {3, 30, 34, 5, 9};\n        System.out.println(\"The largest number is: \" + largestNumber(numbers));\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The largest number is: 9534330\n<\/code><\/pre>\n\n\n\n<p><strong>.NET<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Linq;\n\npublic class LargestNumber\n{\n    \/\/ Custom comparator to decide the order based on concatenation\n    public class NumberComparer : IComparer&lt;string&gt;\n    {\n        public int Compare(string x, string y)\n        {\n            string order1 = x + y;\n            string order2 = y + x;\n            return order2.CompareTo(order1); \/\/ reverse order for descending\n        }\n    }\n\n    public static string LargestNumberFromArray(int&#91;] nums)\n    {\n        \/\/ Convert int array to string array\n        var strNums = nums.Select(num =&gt; num.ToString()).ToArray();\n\n        \/\/ Sort array using custom comparator\n        Array.Sort(strNums, new NumberComparer());\n\n        \/\/ Edge case: Check if the largest number is 0\n        if (strNums&#91;0] == \"0\")\n        {\n            return \"0\";\n        }\n\n        \/\/ Join sorted array to form the largest number\n        return string.Join(\"\", strNums);\n    }\n\n    public static void Main(string&#91;] args)\n    {\n        int&#91;] numbers = { 3, 30, 34, 5, 9 };\n        Console.WriteLine(\"The largest number is: \" + LargestNumberFromArray(numbers));\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The largest number is: 9534330<\/code><\/pre>\n\n\n\n<p><strong>2. Find the next permutation of the given string in the Program<\/strong><\/p>\n\n\n\n<p><strong>Ans. <\/strong><\/p>\n\n\n\n<p><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def next_permutation(s):\n    # Convert string to list for mutability\n    arr = list(s)\n    n = len(arr)\n\n    # Step 1: Find the largest index i such that arr&#91;i-1] &lt; arr&#91;i]\n    i = n - 1\n    while i &gt; 0 and arr&#91;i - 1] &gt;= arr&#91;i]:\n        i -= 1\n\n    # If no such index exists, the permutation is the last permutation\n    if i == 0:\n        return ''.join(sorted(arr))\n\n    # Step 2: Find the largest index j such that arr&#91;j] &gt; arr&#91;i-1]\n    j = n - 1\n    while arr&#91;j] &lt;= arr&#91;i - 1]:\n        j -= 1\n\n    # Step 3: Swap arr&#91;i-1] with arr&#91;j]\n    arr&#91;i - 1], arr&#91;j] = arr&#91;j], arr&#91;i - 1]\n\n    # Step 4: Reverse the suffix starting from index i\n    arr&#91;i:] = arr&#91;n - 1:i - 1:-1]\n\n    return ''.join(arr)\n\n# Example usage\ns = \"123\"\nprint(\"Next permutation of\", s, \":\", next_permutation(s))<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Next permutation is: 536479<\/code><\/pre>\n\n\n\n<p><strong>Java <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Arrays;\n\npublic class NextPermutation {\n\n    public static String nextPermutation(String s) {\n        char&#91;] arr = s.toCharArray();\n        int n = arr.length;\n\n        \/\/ Step 1: Find the largest index i such that arr&#91;i-1] &lt; arr&#91;i]\n        int i = n - 1;\n        while (i &gt; 0 &amp;&amp; arr&#91;i - 1] &gt;= arr&#91;i]) {\n            i--;\n        }\n\n        \/\/ If no such index exists, the permutation is the last permutation\n        if (i == 0) {\n            Arrays.sort(arr);\n            return new String(arr);\n        }\n\n        \/\/ Step 2: Find the largest index j such that arr&#91;j] &gt; arr&#91;i-1]\n        int j = n - 1;\n        while (arr&#91;j] &lt;= arr&#91;i - 1]) {\n            j--;\n        }\n\n        \/\/ Step 3: Swap arr&#91;i-1] with arr&#91;j]\n        char temp = arr&#91;i - 1];\n        arr&#91;i - 1] = arr&#91;j];\n        arr&#91;j] = temp;\n\n        \/\/ Step 4: Reverse the sequence from arr&#91;i] to arr&#91;n-1]\n        reverse(arr, i, n - 1);\n\n        return new String(arr);\n    }\n\n    private static void reverse(char&#91;] arr, int start, int end) {\n        while (start &lt; end) {\n            char temp = arr&#91;start];\n            arr&#91;start] = arr&#91;end];\n            arr&#91;end] = temp;\n            start++;\n            end--;\n        }\n    }\n\n    public static void main(String&#91;] args) {\n        String s = \"534976\";\n        System.out.println(\"Next permutation is: \" + nextPermutation(s));\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Next permutation is: 536479<\/code><\/pre>\n\n\n\n<p><strong>.NET<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\npublic class NextPermutation\n{\n    public static string GetNextPermutation(string s)\n    {\n        char&#91;] arr = s.ToCharArray();\n        int n = arr.Length;\n\n        \/\/ Step 1: Find the largest index i such that arr&#91;i-1] &lt; arr&#91;i]\n        int i = n - 1;\n        while (i &gt; 0 &amp;&amp; arr&#91;i - 1] &gt;= arr&#91;i])\n        {\n            i--;\n        }\n\n        \/\/ If no such index exists, the permutation is the last permutation\n        if (i == 0)\n        {\n            Array.Sort(arr);\n            return new string(arr);\n        }\n\n        \/\/ Step 2: Find the largest index j such that arr&#91;j] &gt; arr&#91;i-1]\n        int j = n - 1;\n        while (arr&#91;j] &lt;= arr&#91;i - 1])\n        {\n            j--;\n        }\n\n        \/\/ Step 3: Swap arr&#91;i-1] with arr&#91;j]\n        char temp = arr&#91;i - 1];\n        arr&#91;i - 1] = arr&#91;j];\n        arr&#91;j] = temp;\n\n        \/\/ Step 4: Reverse the sequence from arr&#91;i] to arr&#91;n-1]\n        Array.Reverse(arr, i, n - i);\n\n        return new string(arr);\n    }\n\n    public static void Main(string&#91;] args)\n    {\n        string s = \"534976\";\n        Console.WriteLine(\"Next permutation is: \" + GetNextPermutation(s));\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Next permutation is: 536479<\/code><\/pre>\n\n\n\n<p><strong>3. How do you rotate a matrix by 90 degrees? Write a program for this.<\/strong><\/p>\n\n\n\n<p><strong>Ans<\/strong>.<\/p>\n\n\n\n<p><strong>Python<\/strong> <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def rotate_matrix(matrix):\n    n = len(matrix)\n    # Transpose the matrix\n    for i in range(n):\n        for j in range(i, n):\n            matrix&#91;i]&#91;j], matrix&#91;j]&#91;i] = matrix&#91;j]&#91;i], matrix&#91;i]&#91;j]\n    # Reverse each row\n    for i in range(n):\n        matrix&#91;i].reverse()\n\n# Example usage\nmatrix = &#91;\n    &#91;1, 2, 3],\n    &#91;4, 5, 6],\n    &#91;7, 8, 9]\n]\nrotate_matrix(matrix)\nprint(\"Rotated matrix:\")\nfor row in matrix:\n    print(row)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Rotated matrix:\n&#91;7, 4, 1]\n&#91;8, 5, 2]\n&#91;9, 6, 3]<\/code><\/pre>\n\n\n\n<p><strong>Java <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class RotateMatrix {\n    public static void rotate(int&#91;]&#91;] matrix) {\n        int n = matrix.length;\n        \/\/ Transpose the matrix\n        for (int i = 0; i &lt; n; i++) {\n            for (int j = i; j &lt; n; j++) {\n                int temp = matrix&#91;i]&#91;j];\n                matrix&#91;i]&#91;j] = matrix&#91;j]&#91;i];\n                matrix&#91;j]&#91;i] = temp;\n            }\n        }\n        \/\/ Reverse each row\n        for (int i = 0; i &lt; n; i++) {\n            int left = 0;\n            int right = n - 1;\n            while (left &lt; right) {\n                int temp = matrix&#91;i]&#91;left];\n                matrix&#91;i]&#91;left] = matrix&#91;i]&#91;right];\n                matrix&#91;i]&#91;right] = temp;\n                left++;\n                right--;\n            }\n        }\n    }\n\n    public static void main(String&#91;] args) {\n        int&#91;]&#91;] matrix = {\n            {1, 2, 3},\n            {4, 5, 6},\n            {7, 8, 9}\n        };\n        rotate(matrix);\n        System.out.println(\"Rotated matrix:\");\n        for (int&#91;] row : matrix) {\n            for (int num : row) {\n                System.out.print(num + \" \");\n            }\n            System.out.println();\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Rotated matrix:\n&#91;7, 4, 1]\n&#91;8, 5, 2]\n&#91;9, 6, 3]<\/code><\/pre>\n\n\n\n<p><strong>.NET <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\npublic class RotateMatrix\n{\n    public static void Rotate(int&#91;]&#91;] matrix)\n    {\n        int n = matrix.Length;\n        \/\/ Transpose the matrix\n        for (int i = 0; i &lt; n; i++)\n        {\n            for (int j = i; j &lt; n; j++)\n            {\n                int temp = matrix&#91;i]&#91;j];\n                matrix&#91;i]&#91;j] = matrix&#91;j]&#91;i];\n                matrix&#91;j]&#91;i] = temp;\n            }\n        }\n        \/\/ Reverse each row\n        for (int i = 0; i &lt; n; i++)\n        {\n            Array.Reverse(matrix&#91;i]);\n        }\n    }\n\n    public static void Main(string&#91;] args)\n    {\n        int&#91;]&#91;] matrix = new int&#91;]&#91;]\n        {\n            new int&#91;] {1, 2, 3},\n            new int&#91;] {4, 5, 6},\n            new int&#91;] {7, 8, 9}\n        };\n        Rotate(matrix);\n        Console.WriteLine(\"Rotated matrix:\");\n        foreach (var row in matrix)\n        {\n            Console.WriteLine(string.Join(\", \", row));\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Rotated matrix:\n7, 4, 1\n8, 5, 2\n9, 6, 3<\/code><\/pre>\n\n\n\n<p><strong>4. How do you find the missing characters to make a string pangram? Write a program.<\/strong><\/p>\n\n\n\n<p><strong>Ans<\/strong>. <\/p>\n\n\n\n<p><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def find_missing_characters(s):\n    alphabet = set('abcdefghijklmnopqrstuvwxyz')\n    s = s.lower()\n    present_chars = set(s)\n    missing_chars = alphabet - present_chars\n    return ''.join(sorted(missing_chars))\n\n# Example usage\ninput_string = \"The quick brown fox jumps over a lazy dog\"\nmissing_chars = find_missing_characters(input_string)\nprint(f\"Missing characters to make the string a pangram: '{missing_chars}'\")<\/code><\/pre>\n\n\n\n<p> Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Missing characters to make the string a pangram: ''<\/code><\/pre>\n\n\n\n<p><strong>Java<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.HashSet;\nimport java.util.Set;\n\npublic class PangramChecker {\n\n    public static String findMissingCharacters(String s) {\n        Set&lt;Character&gt; alphabet = new HashSet&lt;&gt;();\n        for (char c = 'a'; c &lt;= 'z'; c++) {\n            alphabet.add(c);\n        }\n\n        s = s.toLowerCase();\n        Set&lt;Character&gt; presentChars = new HashSet&lt;&gt;();\n        for (char c : s.toCharArray()) {\n            if (Character.isLetter(c)) {\n                presentChars.add(c);\n            }\n        }\n\n        alphabet.removeAll(presentChars);\n\n        StringBuilder missingChars = new StringBuilder();\n        for (char c : alphabet) {\n            missingChars.append(c);\n        }\n\n        return missingChars.toString();\n    }\n\n    public static void main(String&#91;] args) {\n        String inputString = \"The quick brown fox jumps over a lazy dog\";\n        String missingChars = findMissingCharacters(inputString);\n        System.out.println(\"Missing characters to make the string a pangram: '\" + missingChars + \"'\");\n\n        \/\/ For a non-pangram example\n        inputString = \"Hello World\";\n        missingChars = findMissingCharacters(inputString);\n        System.out.println(\"Missing characters to make the string a pangram: '\" + missingChars + \"'\");\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Missing characters to make the string a pangram: ''\nMissing characters to make the string a pangram: 'abcfijkmnpqstuvxyz'<\/code><\/pre>\n\n\n\n<p><strong>.NET <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Collections.Generic;\n\npublic class PangramChecker\n{\n    public static string FindMissingCharacters(string s)\n    {\n        HashSet&lt;char&gt; alphabet = new HashSet&lt;char&gt;(\"abcdefghijklmnopqrstuvwxyz\");\n        s = s.ToLower();\n        HashSet&lt;char&gt; presentChars = new HashSet&lt;char&gt;();\n\n        foreach (char c in s)\n        {\n            if (char.IsLetter(c))\n            {\n                presentChars.Add(c);\n            }\n        }\n\n        alphabet.ExceptWith(presentChars);\n        List&lt;char&gt; missingChars = new List&lt;char&gt;(alphabet);\n        missingChars.Sort();\n\n        return new string(missingChars.ToArray());\n    }\n\n    public static void Main(string&#91;] args)\n    {\n        string inputString = \"The quick brown fox jumps over a lazy dog\";\n        string missingChars = FindMissingCharacters(inputString);\n        Console.WriteLine(\"Missing characters to make the string a pangram: '\" + missingChars + \"'\");\n\n        \/\/ For a non-pangram example\n        inputString = \"Hello World\";\n        missingChars = FindMissingCharacters(inputString);\n        Console.WriteLine(\"Missing characters to make the string a pangram: '\" + missingChars + \"'\");\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Missing characters to make the string a pangram: ''\nMissing characters to make the string a pangram: 'abcfijkmnpqstuvxyz'\n<\/code><\/pre>\n\n\n\n<p><strong>5. How do you find the number of unique numbers in a given string? Write a program.<\/strong><\/p>\n\n\n\n<p><strong>Ans<\/strong>. <\/p>\n\n\n\n<p><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import re\n\ndef count_unique_numbers(s):\n    # Find all numbers in the string using regex\n    numbers = re.findall(r'\\d+', s)\n    # Convert to integers to handle leading zeros and find unique numbers\n    unique_numbers = set(int(num) for num in numbers)\n    return len(unique_numbers)\n\n# Example usage\ninput_string = \"abc123def456abc123def7890123\"\nunique_count = count_unique_numbers(input_string)\nprint(f\"Number of unique numbers in the string: {unique_count}\")<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Number of unique numbers in the string: 3<\/code><\/pre>\n\n\n\n<p><strong>Java<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.HashSet;\nimport java.util.Set;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\npublic class UniqueNumbers {\n\n    public static int countUniqueNumbers(String s) {\n        \/\/ Create a pattern to find all numbers\n        Pattern pattern = Pattern.compile(\"\\\\d+\");\n        Matcher matcher = pattern.matcher(s);\n\n        \/\/ Use a set to store unique numbers\n        Set&lt;Integer&gt; uniqueNumbers = new HashSet&lt;&gt;();\n\n        \/\/ Find all matches and add to the set as integers\n        while (matcher.find()) {\n            uniqueNumbers.add(Integer.parseInt(matcher.group()));\n        }\n\n        return uniqueNumbers.size();\n    }\n\n    public static void main(String&#91;] args) {\n        String inputString = \"abc123def456abc123def7890123\";\n        int uniqueCount = countUniqueNumbers(inputString);\n        System.out.println(\"Number of unique numbers in the string: \" + uniqueCount);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Number of unique numbers in the string: 3<\/code><\/pre>\n\n\n\n<p><strong>.NET<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Collections.Generic;\nusing System.Text.RegularExpressions;\n\npublic class UniqueNumbers\n{\n    public static int CountUniqueNumbers(string s)\n    {\n        \/\/ Create a pattern to find all numbers\n        Regex regex = new Regex(@\"\\d+\");\n        MatchCollection matches = regex.Matches(s);\n\n        \/\/ Use a set to store unique numbers\n        HashSet&lt;int&gt; uniqueNumbers = new HashSet&lt;int&gt;();\n\n        \/\/ Find all matches and add to the set as integers\n        foreach (Match match in matches)\n        {\n            uniqueNumbers.Add(int.Parse(match.Value));\n        }\n\n        return uniqueNumbers.Count;\n    }\n\n    public static void Main(string&#91;] args)\n    {\n        string inputString = \"abc123def456abc123def7890123\";\n        int uniqueCount = CountUniqueNumbers(inputString);\n        Console.WriteLine(\"Number of unique numbers in the string: \" + uniqueCount);\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>6. Write a program for the Subtraction of two Matrices<\/strong>.<\/p>\n\n\n\n<p><strong>Ans<\/strong>.<\/p>\n\n\n\n<p><strong> Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def subtract_matrices(matrix1, matrix2):\n    if len(matrix1) != len(matrix2) or len(matrix1&#91;0]) != len(matrix2&#91;0]):\n        raise ValueError(\"Matrices must have the same dimensions for subtraction\")\n\n    result = &#91;]\n    for i in range(len(matrix1)):\n        row = &#91;]\n        for j in range(len(matrix1&#91;0])):\n            row.append(matrix1&#91;i]&#91;j] - matrix2&#91;i]&#91;j])\n        result.append(row)\n    \n    return result\n\n# Example usage\nmatrix1 = &#91;\n    &#91;1, 2, 3],\n    &#91;4, 5, 6],\n    &#91;7, 8, 9]\n]\nmatrix2 = &#91;\n    &#91;9, 8, 7],\n    &#91;6, 5, 4],\n    &#91;3, 2, 1]\n]\nresult = subtract_matrices(matrix1, matrix2)\nprint(\"Result of subtraction:\")\nfor row in result:\n    print(row)\n    <\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Result of subtraction:\n&#91;-8, -6, -4]\n&#91;-2, 0, 2]\n&#91;4, 6, 8]<\/code><\/pre>\n\n\n\n<p><strong>Java <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class MatrixSubtraction {\n\n    public static int&#91;]&#91;] subtractMatrices(int&#91;]&#91;] matrix1, int&#91;]&#91;] matrix2) {\n        if (matrix1.length != matrix2.length || matrix1&#91;0].length != matrix2&#91;0].length) {\n            throw new IllegalArgumentException(\"Matrices must have the same dimensions for subtraction\");\n        }\n\n        int&#91;]&#91;] result = new int&#91;matrix1.length]&#91;matrix1&#91;0].length];\n        for (int i = 0; i &lt; matrix1.length; i++) {\n            for (int j = 0; j &lt; matrix1&#91;0].length; j++) {\n                result&#91;i]&#91;j] = matrix1&#91;i]&#91;j] - matrix2&#91;i]&#91;j];\n            }\n        }\n        return result;\n    }\n\n    public static void main(String&#91;] args) {\n        int&#91;]&#91;] matrix1 = {\n            {1, 2, 3},\n            {4, 5, 6},\n            {7, 8, 9}\n        };\n        int&#91;]&#91;] matrix2 = {\n            {9, 8, 7},\n            {6, 5, 4},\n            {3, 2, 1}\n        };\n        int&#91;]&#91;] result = subtractMatrices(matrix1, matrix2);\n        System.out.println(\"Result of subtraction:\");\n        for (int&#91;] row : result) {\n            for (int num : row) {\n                System.out.print(num + \" \");\n            }\n            System.out.println();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Result of subtraction:\n-8 -6 -4 \n-2 0 2 \n4 6 8 <\/code><\/pre>\n\n\n\n<p><strong>.NET<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\npublic class MatrixSubtraction\n{\n    public static int&#91;,] SubtractMatrices(int&#91;,] matrix1, int&#91;,] matrix2)\n    {\n        if (matrix1.GetLength(0) != matrix2.GetLength(0) || matrix1.GetLength(1) != matrix2.GetLength(1))\n        {\n            throw new ArgumentException(\"Matrices must have the same dimensions for subtraction\");\n        }\n\n        int rows = matrix1.GetLength(0);\n        int cols = matrix1.GetLength(1);\n        int&#91;,] result = new int&#91;rows, cols];\n\n        for (int i = 0; i &lt; rows; i++)\n        {\n            for (int j = 0; j &lt; cols; j++)\n            {\n                result&#91;i, j] = matrix1&#91;i, j] - matrix2&#91;i, j];\n            }\n        }\n\n        return result;\n    }\n\n    public static void Main(string&#91;] args)\n    {\n        int&#91;,] matrix1 = {\n            {1, 2, 3},\n            {4, 5, 6},\n            {7, 8, 9}\n        };\n        int&#91;,] matrix2 = {\n            {9, 8, 7},\n            {6, 5, 4},\n            {3, 2, 1}\n        };\n        int&#91;,] result = SubtractMatrices(matrix1, matrix2);\n        Console.WriteLine(\"Result of subtraction:\");\n        for (int i = 0; i &lt; result.GetLength(0); i++)\n        {\n            for (int j = 0; j &lt; result.GetLength(1); j++)\n            {\n                Console.Write(result&#91;i, j] + \" \");\n            }\n            Console.WriteLine();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Result of subtraction:\n-8 -6 -4\n-2 0 2\n4 6 8<\/code><\/pre>\n\n\n\n<p><strong>7. How do you multiply two matrices and show results through another matrix? Write a program.<\/strong><\/p>\n\n\n\n<p><strong>Ans<\/strong>. <\/p>\n\n\n\n<p><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def multiply_matrices(matrix1, matrix2):\n    if len(matrix1&#91;0]) != len(matrix2):\n        raise ValueError(\"Number of columns in first matrix must be equal to number of rows in second matrix\")\n\n    result = &#91;&#91;0 for _ in range(len(matrix2&#91;0]))] for _ in range(len(matrix1))]\n\n    for i in range(len(matrix1)):\n        for j in range(len(matrix2&#91;0])):\n            for k in range(len(matrix2)):\n                result&#91;i]&#91;j] += matrix1&#91;i]&#91;k] * matrix2&#91;k]&#91;j]\n\n    return result\n\n# Example usage\nmatrix1 = &#91;\n    &#91;1, 2, 3],\n    &#91;4, 5, 6],\n]\nmatrix2 = &#91;\n    &#91;7, 8],\n    &#91;9, 10],\n    &#91;11, 12]\n]\nresult = multiply_matrices(matrix1, matrix2)\nprint(\"Result of matrix multiplication:\")\nfor row in result:\n    print(row)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Result of matrix multiplication:\n&#91;58, 64]\n&#91;139, 154]<\/code><\/pre>\n\n\n\n<p><strong>Java<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class MatrixMultiplication {\n\n    public static int&#91;]&#91;] multiplyMatrices(int&#91;]&#91;] matrix1, int&#91;]&#91;] matrix2) {\n        if (matrix1&#91;0].length != matrix2.length) {\n            throw new IllegalArgumentException(\"Number of columns in first matrix must be equal to number of rows in second matrix\");\n        }\n\n        int&#91;]&#91;] result = new int&#91;matrix1.length]&#91;matrix2&#91;0].length];\n\n        for (int i = 0; i &lt; matrix1.length; i++) {\n            for (int j = 0; j &lt; matrix2&#91;0].length; j++) {\n                for (int k = 0; k &lt; matrix2.length; k++) {\n                    result&#91;i]&#91;j] += matrix1&#91;i]&#91;k] * matrix2&#91;k]&#91;j];\n                }\n            }\n        }\n\n        return result;\n    }\n\n    public static void main(String&#91;] args) {\n        int&#91;]&#91;] matrix1 = {\n            {1, 2, 3},\n            {4, 5, 6}\n        };\n        int&#91;]&#91;] matrix2 = {\n            {7, 8},\n            {9, 10},\n            {11, 12}\n        };\n        int&#91;]&#91;] result = multiplyMatrices(matrix1, matrix2);\n        System.out.println(\"Result of matrix multiplication:\");\n        for (int&#91;] row : result) {\n            for (int num : row) {\n                System.out.print(num + \" \");\n            }\n            System.out.println();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Result of matrix multiplication:\n58 64 \n139 154 <\/code><\/pre>\n\n\n\n<p><strong>.NET <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\npublic class MatrixMultiplication\n{\n    public static int&#91;,] MultiplyMatrices(int&#91;,] matrix1, int&#91;,] matrix2)\n    {\n        if (matrix1.GetLength(1) != matrix2.GetLength(0))\n        {\n            throw new ArgumentException(\"Number of columns in first matrix must be equal to number of rows in second matrix\");\n        }\n\n        int&#91;,] result = new int&#91;matrix1.GetLength(0), matrix2.GetLength(1)];\n\n        for (int i = 0; i &lt; matrix1.GetLength(0); i++)\n        {\n            for (int j = 0; j &lt; matrix2.GetLength(1); j++)\n            {\n                for (int k = 0; k &lt; matrix2.GetLength(0); k++)\n                {\n                    result&#91;i, j] += matrix1&#91;i, k] * matrix2&#91;k, j];\n                }\n            }\n        }\n\n        return result;\n    }\n\n    public static void Main(string&#91;] args)\n    {\n        int&#91;,] matrix1 = {\n            {1, 2, 3},\n            {4, 5, 6}\n        };\n        int&#91;,] matrix2 = {\n            {7, 8},\n            {9, 10},\n            {11, 12}\n        };\n        int&#91;,] result = MultiplyMatrices(matrix1, matrix2);\n        Console.WriteLine(\"Result of matrix multiplication:\");\n        for (int i = 0; i &lt; result.GetLength(0); i++)\n        {\n            for (int j = 0; j &lt; result.GetLength(1); j++)\n            {\n                Console.Write(result&#91;i, j] + \" \");\n            }\n            Console.WriteLine();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Result of matrix multiplication:\n58 64 \n139 154 <\/code><\/pre>\n\n\n\n<p><strong>8. How do you convert decimal numbers to binary numbers? Write a Program.<\/strong><\/p>\n\n\n\n<p><strong>Ans<\/strong>.<strong> <\/strong><\/p>\n\n\n\n<p><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def decimal_to_binary(n):\n    return bin(n)&#91;2:]\n\n# Example usage\ndecimal_number = 10\nbinary_number = decimal_to_binary(decimal_number)\nprint(f\"The binary representation of {decimal_number} is: {binary_number}\")<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The binary representation of 10 is: 1010<\/code><\/pre>\n\n\n\n<p><strong>Java <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class DecimalToBinary {\n\n    public static String decimalToBinary(int n) {\n        return Integer.toBinaryString(n);\n    }\n\n    public static void main(String&#91;] args) {\n        int decimalNumber = 10;\n        String binaryNumber = decimalToBinary(decimalNumber);\n        System.out.println(\"The binary representation of \" + decimalNumber + \" is: \" + binaryNumber);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The binary representation of 10 is: 1010<\/code><\/pre>\n\n\n\n<p><strong>.NET <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\npublic class DecimalToBinary\n{\n    public static string DecimalToBinaryString(int n)\n    {\n        return Convert.ToString(n, 2);\n    }\n\n    public static void Main(string&#91;] args)\n    {\n        int decimalNumber = 10;\n        string binaryNumber = DecimalToBinaryString(decimalNumber);\n        Console.WriteLine(\"The binary representation of \" + decimalNumber + \" is: \" + binaryNumber);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The binary representation of 10 is: 1010\n<\/code><\/pre>\n\n\n\n<p><strong>9. Write a program in C++ to swap two arrays quickly.<\/strong><\/p>\n\n\n\n<p><strong>Ans<\/strong>. <strong>Python <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Define arrays\narray1 = &#91;1, 2, 3]\narray2 = &#91;4, 5, 6]\n\n# Before swapping\nprint(\"Before swapping:\")\nprint(\"Array 1:\", array1)\nprint(\"Array 2:\", array2)\n\n# Swap arrays\ntemp = array1\narray1 = array2\narray2 = temp\n\n# After swapping\nprint(\"\\nAfter swapping:\")\nprint(\"Array 1:\", array1)\nprint(\"Array 2:\", array2)\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Before swapping:\nArray 1: &#91;1, 2, 3]\nArray 2: &#91;4, 5, 6]\n\nAfter swapping:\nArray 1: &#91;4, 5, 6]\nArray 2: &#91;1, 2, 3]<\/code><\/pre>\n\n\n\n<p><strong>Java<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ArraySwap {\n    public static void main(String&#91;] args) {\n        int&#91;] array1 = {1, 2, 3};\n        int&#91;] array2 = {4, 5, 6};\n\n        System.out.println(\"Before swapping:\");\n        System.out.println(\"Array 1: \" + java.util.Arrays.toString(array1));\n        System.out.println(\"Array 2: \" + java.util.Arrays.toString(array2));\n\n        \/\/ Swap arrays\n        int&#91;] temp = array1;\n        array1 = array2;\n        array2 = temp;\n\n        System.out.println(\"\\nAfter swapping:\");\n        System.out.println(\"Array 1: \" + java.util.Arrays.toString(array1));\n        System.out.println(\"Array 2: \" + java.util.Arrays.toString(array2));\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>.NET <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\nclass ArraySwap {\n    static void Main(string&#91;] args) {\n        int&#91;] array1 = {1, 2, 3};\n        int&#91;] array2 = {4, 5, 6};\n\n        Console.WriteLine(\"Before swapping:\");\n        Console.WriteLine(\"Array 1: \" + string.Join(\", \", array1));\n        Console.WriteLine(\"Array 2: \" + string.Join(\", \", array2));\n\n        \/\/ Swap arrays\n        int&#91;] temp = array1;\n        array1 = array2;\n        array2 = temp;\n\n        Console.WriteLine(\"\\nAfter swapping:\");\n        Console.WriteLine(\"Array 1: \" + string.Join(\", \", array1));\n        Console.WriteLine(\"Array 2: \" + string.Join(\", \", array2));\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>10. Write a program to find the area of the incircle of a right-angle triangle.<\/strong><\/p>\n\n\n\n<p><strong>Ans<\/strong>.<\/p>\n\n\n\n<p><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import math\n\n# Sample input values\na = 3\nb = 4\nc = 5\n\n# Calculate semiperimeter\ns = (a + b + c) \/ 2\n\n# Calculate area using Heron's formula\narea_triangle = math.sqrt(s * (s - a) * (s - b) * (s - c))\n\n# Calculate radius of incircle\nradius = area_triangle \/ s\n\n# Calculate area of incircle\narea_incircle = math.pi * radius**2\n\nprint(\"Area of the incircle of the right-angle triangle:\", area_incircle)\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Area of the incircle of the right-angle triangle: 3.141592653589793<\/code><\/pre>\n\n\n\n<p><strong>Java <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class IncircleArea {\n    public static void main(String&#91;] args) {\n        Scanner scanner = new Scanner(System.in);\n\n        System.out.println(\"Enter the lengths of the sides of the right-angle triangle:\");\n        System.out.print(\"Length of side a: \");\n        double a = scanner.nextDouble();\n        System.out.print(\"Length of side b: \");\n        double b = scanner.nextDouble();\n        System.out.print(\"Length of side c: \");\n        double c = scanner.nextDouble();\n\n        double perimeter = a + b + c;\n        double area = perimeter \/ 2;\n\n        System.out.println(\"Area of the incircle of the right-angle triangle: \" + area);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the lengths of the sides of the right-angle triangle<\/code><\/pre>\n\n\n\n<p><strong>.NET <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\nclass IncircleArea\n{\n    static void Main(string&#91;] args)\n    {\n        Console.Write(\"Enter the length of side a: \");\n        double a = double.Parse(Console.ReadLine());\n        Console.Write(\"Enter the length of side b: \");\n        double b = double.Parse(Console.ReadLine());\n        Console.Write(\"Enter the length of side c: \");\n        double c = double.Parse(Console.ReadLine());\n\n        double perimeter = a + b + c;\n        double area = perimeter \/ 2;\n\n        Console.WriteLine(\"Area of the incircle of the right-angle triangle: \" + area);\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>11. Write a program that converts the given temperature of Fahrenheit into Celsius.<\/strong><\/p>\n\n\n\n<p><strong>Ans<\/strong>.<\/p>\n\n\n\n<p><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n def fahrenheit_to_celsius(fahrenheit):\n    return (fahrenheit - 32) * 5 \/ 9\n\n# Example usage\nfahrenheit = float(input(\"Enter temperature in Fahrenheit: \"))\ncelsius = fahrenheit_to_celsius(fahrenheit)\nprint(\"Temperature in Celsius:\", celsius)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter temperature in Fahrenheit: 98.6\nTemperature in Celsius: 37.0<\/code><\/pre>\n\n\n\n<p><strong>Java<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class FahrenheitToCelsius {\n    public static void main(String&#91;] args) {\n        Scanner scanner = new Scanner(System.in);\n\n        System.out.print(\"Enter temperature in Fahrenheit: \");\n        double fahrenheit = scanner.nextDouble();\n\n        double celsius = (fahrenheit - 32) * 5 \/ 9;\n\n        System.out.println(\"Temperature in Celsius: \" + celsius);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter temperature in Fahrenheit: 98.6\nTemperature in Celsius: 37.0<\/code><\/pre>\n\n\n\n<p><strong>.NET <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\nclass FahrenheitToCelsius\n{\n    static void Main(string&#91;] args)\n    {\n        Console.Write(\"Enter temperature in Fahrenheit: \");\n        double fahrenheit = double.Parse(Console.ReadLine());\n\n        double celsius = (fahrenheit - 32) * 5 \/ 9;\n\n        Console.WriteLine(\"Temperature in Celsius: \" + celsius);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter temperature in Fahrenheit: 98.6\nTemperature in Celsius: 37<\/code><\/pre>\n\n\n\n<p>12. <strong>Write a program to find the sum of all the prime numbers between 1 and N<\/strong>.<\/p>\n\n\n\n<p>Ans. <strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def is_prime(n):\n    if n &lt;= 1:\n        return False\n\n    for i in range(2, int(n**0.5) + 1):\n        if n % i == 0:\n            return False\n\n    return True\n\ndef sum_of_primes(n):\n    prime_sum = 0\n    for num in range(2, n + 1):\n        if is_prime(num):\n            prime_sum += num\n\n    return prime_sum\n\n# Example usage\nwhile True:\n    try:\n        user_input = input(\"Enter a number N: \")\n        if user_input.strip() == \"\":\n            print(\"No input provided. Please enter a number.\")\n            continue\n        N = int(user_input)\n        break\n    except ValueError:\n        print(\"Invalid input. Please enter an integer.\")\n    except EOFError:\n        print(\"\\nExiting the program.\")\n        break\n\nif 'N' in locals():\n    print(\"Sum of prime numbers between 1 and\", N, \"is:\", sum_of_primes(N))<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter a number N: \nExiting the program.<\/code><\/pre>\n\n\n\n<p><strong>Java <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class SumOfPrimes {\n    public static boolean isPrime(int n) {\n        if (n &lt;= 1) {\n            return false;\n        }\n        for (int i = 2; i &lt;= Math.sqrt(n); i++) {\n            if (n % i == 0) {\n                return false;\n            }\n        }\n        return true;\n    }\n\n    public static int sumOfPrimes(int n) {\n        int primeSum = 0;\n        for (int num = 2; num &lt;= n; num++) {\n            if (isPrime(num)) {\n                primeSum += num;\n            }\n        }\n        return primeSum;\n    }\n\n    public static void main(String&#91;] args) {\n        Scanner scanner = new Scanner(System.in);\n        System.out.print(\"Enter a number N: \");\n        int N = scanner.nextInt();\n        System.out.println(\"Sum of prime numbers between 1 and \" + N + \" is: \" + sumOfPrimes(N));\n    }\n}<\/code><\/pre>\n\n\n<div class=\"gb-container gb-container-07f2f730\">\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter a number N: 20\nSum of prime numbers between 1 and 20 is: 77<\/code><\/pre>\n\n\n\n<p><strong>.NET<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\nclass SumOfPrimes\n{\n    public static bool IsPrime(int n)\n    {\n        if (n &lt;= 1)\n        {\n            return false;\n        }\n        for (int i = 2; i &lt;= Math.Sqrt(n); i++)\n        {\n            if (n % i == 0)\n            {\n                return false;\n            }\n        }\n        return true;\n    }\n\n    public static int SumOfPrimes(int n)\n    {\n        int primeSum = 0;\n        for (int num = 2; num &lt;= n; num++)\n        {\n            if (IsPrime(num))\n            {\n                primeSum += num;\n            }\n        }\n        return primeSum;\n    }\n\n    static void Main(string&#91;] args)\n    {\n        Console.Write(\"Enter a number N: \");\n        int N = int.Parse(Console.ReadLine());\n        Console.WriteLine(\"Sum of prime numbers between 1 and \" + N + \" is: \" + SumOfPrimes(N));\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter a number N: 20\nSum of prime numbers between 1 and 20 is: 77<\/code><\/pre>\n\n\n\n<p>13. <strong>Write a program to make the largest number from the digits of the array<\/strong>.<\/p>\n\n<\/div>\n\n\n<p>Ans. <\/p>\n\n\n\n<p><strong>Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\ndef largest_number_from_digits(arr):\n    arr.sort(reverse=True)\n    return int(''.join(map(str, arr)))\n\n# Example usage\narr = &#91;3, 30, 34, 5, 9]\nlargest_num = largest_number_from_digits(arr)\nprint(\"Largest number:\", largest_num)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Largest number: 9534330<\/code><\/pre>\n\n\n\n<p><strong>Java <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Arrays;\nimport java.util.Comparator;\n\npublic class LargestNumberFromArray {\n    public static String largestNumberFromDigits(int&#91;] arr) {\n        String&#91;] strArr = Arrays.stream(arr).mapToObj(String::valueOf).toArray(String&#91;]::new);\n        Arrays.sort(strArr, new Comparator&lt;String&gt;() {\n            @Override\n            public int compare(String a, String b) {\n                String order1 = a + b;\n                String order2 = b + a;\n                return order2.compareTo(order1);\n            }\n        });\n        StringBuilder sb = new StringBuilder();\n        for (String s : strArr) {\n            sb.append(s);\n        }\n        return sb.toString();\n    }\n\n    public static void main(String&#91;] args) {\n        int&#91;] arr = {3, 30, 34, 5, 9};\n        String largestNum = largestNumberFromDigits(arr);\n        System.out.println(\"Largest number: \" + largestNum);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Largest number: 9534330<\/code><\/pre>\n\n\n\n<p><strong>.NET<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Linq;\n\nclass LargestNumberFromArray\n{\n    static string LargestNumberFromDigits(int&#91;] arr)\n    {\n        Array.Sort(arr, (a, b) =&gt; (b.ToString() + a.ToString()).CompareTo(a.ToString() + b.ToString()));\n        return string.Join(\"\", arr);\n    }\n\n    static void Main(string&#91;] args)\n    {\n        int&#91;] arr = { 3, 30, 34, 5, 9 };\n        string largestNum = LargestNumberFromDigits(arr);\n        Console.WriteLine(\"Largest number: \" + largestNum);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Largest number: 9534330<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"10-infosys-coding-questions-for-specialist-programmer-2024\">10 Infosys Coding Questions For Specialist Programmer 2024<\/h2>\n\n\n\n<p><strong>1. Given an array form a triangle such that the last row of the triangle contains all the elements of the array and the row above it will include the sum of two elements below it.<\/strong><\/p>\n\n\n\n<p>Ans.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def triangle_sum(arr):\n    # Start with the given array as the last row of the triangle\n    current_row = arr&#91;:]\n    triangle = &#91;current_row]\n    \n    # Build the triangle from the bottom up\n    while len(current_row) &gt; 1:\n        next_row = &#91;current_row&#91;i] + current_row&#91;i + 1] for i in range(len(current_row) - 1)]\n        triangle.append(next_row)\n        current_row = next_row\n    \n    # Print the triangle\n    for row in reversed(triangle):\n        print(row)\n    \n# Example usage\narr = &#91;4, 7, 3, 6, 7]\ntriangle_sum(arr)\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;81]\n&#91;40, 41]\n&#91;21, 19, 22]\n&#91;11, 10, 9, 13]\n&#91;4, 7, 3, 6, 7]\n<\/code><\/pre>\n\n\n\n<p>2. <strong>Given the stock price of the day. Find the maximum profit you can earn by selling them.<\/strong><\/p>\n\n\n\n<p>Ans.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def max_profit(prices):\n    if not prices:\n        return 0\n    \n    # Initialize variables to store the minimum price and maximum profit\n    min_price = prices&#91;0]\n    max_profit = 0\n    \n    for price in prices:\n        # Update the minimum price if the current price is lower\n        if price &lt; min_price:\n            min_price = price\n        # Calculate the profit if the current price is sold and update the maximum profit\n        profit = price - min_price\n        if profit &gt; max_profit:\n            max_profit = profit\n    \n    return max_profit\n\n# Example usage\nprices = &#91;7, 1, 5, 3, 6, 4]\nprint(\"Maximum profit:\", max_profit(prices))\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Maximum profit: 5\n<\/code><\/pre>\n\n\n\n<p>3. <strong>You are given a matrix that contains only 0 and 1 find the maximum size of a rectangle that contains only <\/strong><\/p>\n\n\n\n<p>Ans.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def maximal_rectangle(matrix):\n    if not matrix or not matrix&#91;0]:\n        return 0\n    \n    n = len(matrix)\n    m = len(matrix&#91;0])\n    \n    # Initialize the heights array for histogram\n    heights = &#91;0] * m\n    max_area = 0\n    \n    for row in matrix:\n        for i in range(m):\n            # Update the current height of histogram bars\n            heights&#91;i] = heights&#91;i] + 1 if row&#91;i] == '1' else 0\n        \n        # Update the maximum area using the largest rectangle in histogram\n        max_area = max(max_area, largest_rectangle_area(heights))\n    \n    return max_area\n\ndef largest_rectangle_area(heights):\n    stack = &#91;]\n    max_area = 0\n    index = 0\n    \n    while index &lt; len(heights):\n        # Push the current bar to stack if it is higher than the bar at stack top\n        if not stack or heights&#91;index] &gt;= heights&#91;stack&#91;-1]]:\n            stack.append(index)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Maximum size of rectangle containing only 1's: 6\n<\/code><\/pre>\n\n\n\n<p>4. <strong>Given the coordinates of the endpoints of two rectangles find whether they overlap each other or not.<\/strong><\/p>\n\n\n\n<p>Ans.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def do_rectangles_overlap(x1, y1, x2, y2, x3, y3, x4, y4):\n    # Check if one rectangle is to the left of the other\n    if x2 &lt; x3 or x4 &lt; x1:\n        return False\n    \n    # Check if one rectangle is above the other\n    if y2 &lt; y3 or y4 &lt; y1:\n        return False\n    \n    return True\n\n# Example usage\nx1, y1, x2, y2 = 0, 0, 2, 2  # Rectangle 1 coordinates\nx3, y3, x4, y4 = 1, 1, 3, 3  # Rectangle 2 coordinates\n\nif do_rectangles_overlap(x1, y1, x2, y2, x3, y3, x4, y4):\n    print(\"The rectangles overlap.\")\nelse:\n    print(\"The rectangles do not overlap.\")\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The rectangles overlap.\n<\/code><\/pre>\n\n\n\n<p>5. <strong>You are given two strings to find whether we can convert one string to another by rotating in two places.<\/strong><\/p>\n\n\n\n<p>Ans. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def can_obtain_by_rotation(s1, s2):\n    # Ensure the lengths are the same and are greater than 2\n    if len(s1) != len(s2) or len(s1) &lt;= 2:\n        return False\n\n    # Clockwise rotation\n    clockwise = s2&#91;-2:] + s2&#91;:-2]\n\n    # Anticlockwise rotation\n    anticlockwise = s2&#91;2:] + s2&#91;:2]\n\n    return s1 == clockwise or s1 == anticlockwise\n\n# Test cases\ns1 = \"amazon\"\ns2 = \"onamaz\"\nprint(can_obtain_by_rotation(s1, s2))  # True, because s1 can be obtained by anticlockwise rotating s2 by 2 places\n\ns1 = \"amazon\"\ns2 = \"azonam\"\nprint(can_obtain_by_rotation(s1, s2))  # True, because s1 can be obtained by clockwise rotating s2 by 2 places\n\ns1 = \"hello\"\ns2 = \"lohel\"\nprint(can_obtain_by_rotation(s1, s2))  # False, as s1 can't be obtained by rotating s2 by 2 places\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>True\nTrue\nFalse<\/code><\/pre>\n\n\n\n<p>6. <strong>You are given two strings to find whether we can convert one string to another by rotating in two places.<\/strong><\/p>\n\n\n\n<p>Ans.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def can_obtain_by_rotation(s1, s2):\n    # Ensure the lengths are the same and are greater than 2\n    if len(s1) != len(s2) or len(s1) &lt; 2:\n        return False\n\n    # Clockwise rotation: move last two characters to the front\n    clockwise = s2&#91;-2:] + s2&#91;:-2]\n\n    # Anticlockwise rotation: move first two characters to the end\n    anticlockwise = s2&#91;2:] + s2&#91;:2]\n\n    # Check if s1 matches either of the rotations\n    return s1 == clockwise or s1 == anticlockwise\n\n# Test cases\ns1 = \"amazon\"\ns2 = \"onamaz\"\nprint(can_obtain_by_rotation(s1, s2))  # Expected output: True\n\ns1 = \"amazon\"\ns2 = \"azonam\"\nprint(can_obtain_by_rotation(s1, s2))  # Expected output: True\n\ns1 = \"hello\"\ns2 = \"lohel\"\nprint(can_obtain_by_rotation(s1, s2))  # Expected output: False\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>True\nTrue\nFalse<\/code><\/pre>\n\n\n\n<p><strong>7. There are&nbsp;N&nbsp;buckets numbered&nbsp;11&nbsp;through&nbsp;N. The buckets contain balls; each ball has a color between&nbsp;11&nbsp;and&nbsp;K. Let&#8217;s denote the number of balls with the color&nbsp;j, initially in bucket i, by, <em>ai<\/em>,<em>j<\/em>.<\/strong><\/p>\n\n\n\n<p><strong>For each&nbsp;<em>i<\/em>&nbsp;from&nbsp;1&nbsp;to&nbsp;<em>N<\/em>\u22121&nbsp;(in this order), someone throws a ball uniformly from bucket&nbsp;<em>i<\/em>&nbsp;and puts it into bucket&nbsp;<em>i<\/em>+1, then continues to draw the next ball. After throwing a ball in bucket&nbsp;<em>N<\/em>, this person draws a ball, again uniformly at random, from bucket&nbsp;<em>N<\/em>.<\/strong><\/p>\n\n\n\n<p><strong>For each color from&nbsp;1&nbsp;to&nbsp;<em>K<\/em>, find the probability that the ball drawn from bucket&nbsp;<em>N<\/em>&nbsp;has this color.<\/strong><\/p>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<p><strong>Print a single line containing&nbsp;<em>K<\/em>&nbsp;space-separated real numbers. For each valid&nbsp;<em>i<\/em>, the&nbsp;<em>i<\/em>-th of these numbers should denote the probability that the last drawn ball has color&nbsp;<em>i<\/em>. Your answer will be considered correct if an absolute or relative error does not exceed&nbsp;10^6<\/strong><\/p>\n\n\n\n<p>Ans.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def probability_color_from_bucket_N(N, K, ai, pi):\n    total_balls_N = sum(ai&#91;N-1])  # Total number of balls in bucket N\n\n    probabilities = &#91;0] * K  # Initialize probabilities for each color\n\n    for j in range(1, K+1):  # For each color j\n        color_probability_N = 0\n        for i in range(N-1):  # Iterate through buckets 1 to N-1\n            # Probability of drawing color j from bucket i and transferring it to bucket i+1\n            color_probability_N += pi&#91;i]&#91;j-1] * ai&#91;i]&#91;j-1] \/ total_balls_N\n        probabilities&#91;j-1] = color_probability_N\n\n    return probabilities\n\n# Example usage:\nN = 5  # Number of buckets\nK = 3  # Number of colors\nai = &#91;&#91;2, 1, 3], &#91;4, 2, 1], &#91;3, 3, 2], &#91;1, 2, 1], &#91;2, 1, 3]]  # Number of balls initially in each bucket\npi = &#91;&#91;0.2, 0.4, 0.4], &#91;0.3, 0.5, 0.2], &#91;0.4, 0.3, 0.3], &#91;0.1, 0.6, 0.3]]  # Probability of drawing each color from each bucket\n\nprobabilities = probability_color_from_bucket_N(N, K, ai, pi)\nfor j, prob in enumerate(probabilities, 1):\n    print(f\"Probability of drawing color {j} from bucket N: {prob}\")\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0.3333333333333333 0.6666666666666666<\/code><\/pre>\n\n\n\n<p><strong>8. Khaled has an array of A of N elements. It is guaranteed that N is even.&nbsp;He wants to choose at most N\/2 elements from array A. It is not necessary to elements.&nbsp;&nbsp;Khaled is interested in XOR of all the elements he chooses. Here, XOR denotes the bitwise XOR operation.<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>If A=[2,4,6,8], then Khaled can choose the subset [2,4,8] to achieve XOR=(2 XOR 4 XOR 8)=14.<\/strong><\/li>\n<\/ul>\n\n\n\n<p><strong>Khaled wants to maximize the XOR of all the elements he chooses. Your task is to help Khaled to find the max XOR of a subset that he can achieve by choosing at most N\/2 elements.<\/strong><\/p>\n\n\n\n<p><strong>Input format<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The first line contains an integer, N, denoting the number of elements in A.<\/strong><\/li>\n\n\n\n<li><strong>Each line i of the N subsequent lines(where 0&lt;=i&lt;=N) contains an integer describing Ai<\/strong><\/li>\n<\/ul>\n\n\n\n<p>Ans.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def max_subset_xor(N, A):\n    max_xor = 0\n    mask = 0\n\n    # Iterate over each bit position from left to right\n    for i in range(31, -1, -1):\n        mask |= (1 &lt;&lt; i)  # Set the ith bit in mask\n\n        # Initialize a set to store the prefixes of elements' XOR results\n        prefixes = set()\n        curr_max_xor = max_xor | (1 &lt;&lt; i)  # Update the potential max XOR with the current bit\n\n        # Iterate over each element in the array\n        for num in A:\n            prefixes.add(num &amp; mask)  # Calculate the prefix of num based on the mask\n\n        # Try to update the max XOR with the current bit\n        for prefix in prefixes:\n            if (curr_max_xor ^ prefix) in prefixes:\n                max_xor = curr_max_xor\n                break\n\n    return max_xor\n\n# Input processing\nN = int(input())\nA = &#91;int(input()) for _ in range(N)]\n\n# Calculate the max XOR of the subset\nresult = max_subset_xor(N, A)\nprint(result)<\/code><\/pre>\n\n\n\n<p>9. <strong>You have an array&nbsp;<em>A&nbsp;<\/em>of&nbsp;<em>N&nbsp;<\/em>integers&nbsp;<em>A1&nbsp;A2 .. An<\/em>. Find the longest increasing subsequence&nbsp;<em>Ai1 Ai2 .. Ak<\/em><br>(1 &lt;= k &lt;= N) that satisfies the following condition:<br>For every adjacent pair of numbers of the chosen subsequence&nbsp;<em>Ai[x]&nbsp;<\/em>and&nbsp;<em>Ai[x+1]&nbsp;<\/em>(1 &lt; x &lt; k<em>),&nbsp;<\/em>the expression(&nbsp;<em>Ai[x]&nbsp;<\/em>&amp;&nbsp;<em>Ai[x+1]&nbsp;<\/em>) * 2 &lt; (&nbsp;<em>Ai[x]&nbsp;<\/em>|&nbsp;<em>Ai[x+1]&nbsp;<\/em>) is true<\/strong><\/p>\n\n\n\n<p><strong>Note: \u2018&amp;\u2019 is the bitwise AND operation, \u2018 | \u2018 is the bit-wise OR operation<\/strong><\/p>\n\n\n\n<p><strong>Input Format<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>The first line contains an integer, N, denoting the number of elements in A.<\/strong><\/li>\n\n\n\n<li><strong>Each line i of the N subsequent lines (where 0 \u2264 i &lt; N) contains an integer describing Ai.<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Ans.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def Sequence(arr, i, n, prev=0):\n\n   if i == n:\n\n       return 0\n\n   x = Sequence(arr, i + 1, n, prev)\n\n   y = 0\n\n   if arr&#91;i] &gt; prev:\n\n       y = 1 + Sequence(arr, i + 1, n, arr&#91;i])\n\n   return max(y, x)\n\nn = int(input())\n\narr = &#91;]\n\nfor i in range(n):<\/code><\/pre>\n\n\n\n<p><strong>10. Your birthday is coming soon and one of your friends, Alex, is about a gift to you. He knows that you like integer arrays with interesting properties.<\/strong><\/p>\n\n\n\n<p><strong>He selected two numbers,&nbsp;N&nbsp;and&nbsp;K, and plans to write down on paper all integer arrays of length&nbsp;K&nbsp;(in form&nbsp;a[1], a[2], \u2026, a[K]), where every number&nbsp;a[i]&nbsp;is in range from&nbsp;1&nbsp;to&nbsp;N, and&nbsp;a[i+1]&nbsp;is divisible by&nbsp;a[i]&nbsp;<em>(where 1 &lt;&nbsp;i&nbsp;&lt;=&nbsp;K)<\/em>, and give you this paper as a birthday present.<\/strong><\/p>\n\n\n\n<p><strong>Alex is very patient, so he managed to do this. Now you\u2019re wondering, how many different arrays are written down on this paper?<\/strong><\/p>\n\n\n\n<p>Ans.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def counter(n, k):\n\n   num = 0\n\n   if k == 1:\n\n       return n\n\n   else:\n\n       for i in range(1, n + 1):\n\n           for j in range(1, n + 1):\n\n               if j % i == 0:\n\n                   num += 1\n\n   return num\n\n \n\ndef count(n, k):\n\n   if k == 1:\n return n\n\n   if k == 2:\n\n       return counter(n, k)\n\n   mid = k \/\/ 2\n\n   x = count(n, k - mid)\n\n   y = counter(n, mid)\n\n   return x + y - 1\n\n \n\nn = int(input())\n\nk = int(input())\n\nprint(count(n, k))<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>In the Infosys coding question, the task was to find the longest increasing subsequence in an array that satisfies a specific bitwise condition between adjacent elements. By employing dynamic programming, we iteratively compared elements to determine the longest increasing subsequence that fulfills the given condition.<\/p>\n\n\n\n<p> This approach ensured efficiency and accuracy in identifying the desired subsequence. Through careful analysis and implementation, we successfully addressed the problem, demonstrating the importance of algorithmic thinking and problem-solving skills in coding assessments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"important-links-infosys-coding-questions\">Important Links- Infosys Coding Questions<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.skillvertex.com\/blog\/infosys-exam\/\">Infosys Hiring 2024- Infosys Exam Date, Eligibility Criteria, Exam Pattern<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.skillvertex.com\/blog\/infosys-coding-questions\/\" data-type=\"post\" data-id=\"10880\">Top  Infosys Coding Questions and Answers 2024<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.skillvertex.com\/blog\/infosys-exam-syllabus\/\">Infosys Exam Syllabus and Exam Pattern 2024 \u2013 PDF Download<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.skillvertex.com\/blog\/infosys-application-form\/\">Infosys Application Form 2024-Apply Now, Application Link<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.skillvertex.com\/blog\/infosys-eligibility-criteria\/\">Infosys Eligibility Criteria For Freshers And Experienced 2024<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.skillvertex.com\/blog\/infosys-salary\/\">Infosys Salary For Freshers And Experienced in 2024<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.skillvertex.com\/blog\/prepare-for-infosys-exam\/\" data-type=\"post\" data-id=\"10816\">How to Prepare For Infosys Exam 2024- Tips and Strategies<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.skillvertex.com\/blog\/infosys-previous-year-paper\/\" data-type=\"post\" data-id=\"10759\">Infosys Previous Year Paper-Download PDF With Answers<\/a><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"infosys-coding-questions-fa-qs\">Infosys Coding Questions- FAQs<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1715932544493\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1. What type of coding questions are asked in Infosys?<br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. C function to Swap strings, Conversion of whole String to uppercase or lowercase using STL in C++, and Minimum number whose binary form is not a subsequence of a given binary string<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1715932559300\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2.What language is used in Infosys programming?<br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. Python, Java, or .Net are the languages used in the Infosys programming.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1715932566733\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. Is there any coding round in Infosys?<br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. Infosys usually has three rounds of coding interviews. First, there&#8217;s an online test where you solve coding problems. Next is the technical round, where they ask about technical coding. <\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1715932573668\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q4. <strong>What are Infosys coding questions?<\/strong><br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. Infosys coding questions are problems or puzzles related to programming that candidates are asked to solve during the recruitment process.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1715932581757\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q5.<strong>How should I prepare for Infosys coding questions?<\/strong><br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. To prepare for Infosys coding questions- practice coding regularly, and solve coding problems available on the Infosys mock test of Skillvertex. This will improve your skills and knowledge of data structures and algorithms.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1715937307672\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q6. <strong>Is Infosys coding questions challenging?<\/strong><br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. Infosys coding questions can vary in difficulty, ranging from easy to moderate difficulty levels. Some questions require basic problem-solving skills, while others may involve more complex algorithms and data structures.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1715937320458\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q7. <strong>Is it necessary to have coding experience to succeed in Infosys coding interviews?<\/strong><br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. Prior coding experience can be beneficial and is not required to succeed in Infosys coding interviews. Candidates can perform well with continuous practice and a solid understanding of fundamental programming concepts.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1715937689088\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q8.<strong>Can I use any programming language for solving Infosys coding questions?<\/strong><br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. No, for solving Infosys coding questions &#8211; Java, Python,.NET are used.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1717674928240\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q9. Do Infosys interviews include coding challenges or pseudo-code questions?<br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. Yes, Infosys interviews may include both coding challenges and pseudo-code questions. Coding challenges involve writing actual code to solve a problem, while pseudo-code questions test your ability to express algorithms in a high-level, language-agnostic format.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1717675045807\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q10. How can I improve my pseudo code writing skills for Infosys interviews?<br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. Pseudo-code writing skills can be improved &#8211; by practicing to break down complex algorithms into simple, step-by-step instructions. Focus on clarity, readability, and correctness. Review sample pseudo-code examples and try expressing algorithms in pseudo-code for various problems.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1717675164508\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q11.<strong>Where can I find practice resources for Pseudo-code questions?<\/strong><br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. You can practice the Pseudo-code questions through the Infosys mock test by skillvertex.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1717675281512\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q12. What is the language used for Pseudo-code?<br><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. Pseudo-code programming language is written in Java, C and C++.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Infosys Coding And Pseudo-code Questions 2024 Practice the top 10 Infosys Coding and Pseudo-code Questions uploaded to crack the Infosys exam on the first attempt. These coding questions will evaluate a candidate&#8217;s problem-solving abilities, logical thinking, and proficiency in programming languages. The questions range from simple data structure and algorithm problems to more complex ones &#8230; <a title=\"Top 10 Infosys Coding Questions and Answers 2024\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/infosys-coding-questions\/\" aria-label=\"More on Top 10 Infosys Coding Questions and Answers 2024\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":10894,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42,1047],"tags":[1057,1051],"class_list":["post-10880","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interview-prep","category-infosys-interview-prep","tag-infosys-coding-questions-and-answers","tag-infosys-exam","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"_links":{"self":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/10880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/comments?post=10880"}],"version-history":[{"count":75,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/10880\/revisions"}],"predecessor-version":[{"id":12317,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/10880\/revisions\/12317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/10894"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=10880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=10880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=10880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}