Answer:
- public class Main {
-
- public static void main (String [] args) {
- int[][] myArray = {{1,5,6}, {7, 9, 2}};
- fixArray(myArray, 1, 2, 12);
-
- System.out.println(myArray[1][2]);
- }
-
-
- private static void fixArray(int[][] array, int row, int col, int value){
- array[row][col] = value;
- }
- }
Explanation:
The solution code is written in Java.
Firstly, create the method fixArray with that takes four inputs, array, row, col and value (Line 11). Within the method body, use row and col as index to address a particular element from array and set the input value to it (Line 12).
Next, we test the method in the main program using a sample array (Line 4) and we try to change the row-1 and col-2 element from 2 to 12 (Line 5).
The print statement in Line 7 will display 12 in console.
Answer:
You can simplify the problem down by recognizing that you just need to keep track of the integers you've seen in array that your given. You also need to account for edge cases for when the array is empty or the value you get would be greater than your max allowed value. Finally, you need to ensure O(n) complexity, you can't keep looping for every value you come across. This is where the boolean array comes in handy. See below -
public static int solution(int[] A)
{
int min = 1;
int max = 100000;
boolean[] vals = new boolean[max+1];
if(A.length == 0)
return min;
//mark the vals array with the integers we have seen in the A[]
for(int i = 0; i < A.length; i++)
{
if(A[i] < max + 1)
vals[A[i]] = true;
}
//start at our min val and loop until we come across a value we have not seen in A[]
for (int i = 1; i < max; i++)
{
if(vals[i] && min == i)
min++;
else if(!vals[i])
break;
}
if(min > max)
return max;
return min;
}
Answer:
the consecutive two elements and swap them based on the value which is larger if we go for ascending order
Explanation:
bubble sort compares 2 consecutive elements of the list and swap them. in one iteration one value will be placed correctly depending on the sorting order either ascending or descending
The horizontal parity check
The horizontal parity check or the longitudinal parity check/Longitudinal redundancy check is the count of odd or even parity for all bits in a message. This process acts a precaution against transmission error. Additionally, this parity check is performed on a serial sequence of binary digits recorded on a single track of data medium or arrive in serial sequence on a single wire.
In python 3.8:
print("\"Computer Science is no more about \ncomputers\nthan astronomy is about telescopes\"\n-Edsger W. Dijkstra")
I hope this helps!