jassi.srmcem
BAN USERCan you provide some more details. As in - any ratio that needs to be maintained ?
- jassi.srmcem May 04, 2014@Srinivas -
There can be any expression which includes multiplication.
For eg. - ((a+b)((c+d)+e))
In this expression we have 3 operators and 4 opening braces and also doesn't include any duplicates. And according to your algo it would fail.
@Miral - Sorry that was a big miss-
Considered two examples
Eg1 - ((a+b)+((c+d)))
eg2 - (((a+b) + cc))
and I changed my algo to-
Step 1 - Store the index of '(' in an 'opening_paren' array from the expression.
Step 2 - On occurrence of ')' store its index in a 'closing_paren' array and now check for the next index and if the next index is also ')' then calculate the difference in indexes and if the last two elements of both array have difference in index as 1 then it means duplicate.
Lets see the below example -
eg1- (((a+b) + c))
opening_paren
0
1
2
closing_paren
6
and 7 index is not ')' i remove 2 and 6 from the list
opening_paren
0
1
closing_paren
9
10
Now as we can see the difference between indexes is 1 on both the arrays which would lead to duplicate parenthesis.
@Miral and @Sehs -
For finding duplicate parenthesis... this simple means your statement would be having "((" i.e., two starting parenthesis... once you find this.. find the next closing parenthesis.. ')' and if the next character in the string is also ')' then this means duplicate parenthesis exist...
@Miral and @Sehs -
For finding duplicate parenthesis... this simple means your statement would be having "((" i.e., two starting parenthesis... once you find this.. find the next closing parenthesis.. ')' and if the next character in the string is also ')' then this means duplicate parenthesis exist...
expressionString = (( a + b ) + (( c + d )))
Step1 : In the expression look for "((" and store in a string - subStr
Step2: Look for the next occurrence of ')' and store its index
Step3: Look for the character at index+1
if(expressionString.charAt(index+1) == ')'){
print("expression contains duplicate parenthesis ");
break;
}
else{
subStr = " ";
}
in this what is the use case... i mean if my number is 5,
Then what numbers should be the output?
I have a array A[] = {1,2,5,10,11,3,9}
n is the length of A; n = A.length
with an exemption n >=3
A[k]= 5
A[k-1] = 2
A[k-2] = 1
previous = A[k-2]; 2
max(A[k-1],A[k-2]) = 2
max(A[k-1],A[k-2]) + A[k] on a condition max(A[k-1],A[k-2]) != previous
if(max(A[k-1],A[k-2]) != previous)
{
sum[counter] = max(A[k-1],A[k-2]) + A[k]
counter++;
}else
{
sum[counter] = A[k]
counter++;
}
previous = A[k-2]
After this iterate over sum array and find the maximum number.
I didnt get the question -
There will be condition in which a node can either add, reject or override the value. What is that?
How will a node determine when to add, when to override and when to add to its own value?
Use regular expression in this -
String arr[] = str.split("\\s+");
for(int i =0; i< arr.length; i++){
String a = arr[i];
if(arr[i].length() > 1){
for(int j = arr[i].length() -1; j >= 0 ; j--){
System.out.print(a.charAt(j));
}
}else{
System.out.println(arr[i]);
}
}
If this is the question then my ans is -
- jassi.srmcem May 05, 2014Step 1 : Consider m*n matrix A[M][N]
Step 2 : Find the sum of all the rows and store it in a map sum[row_number, sum]
Step 3 : As mentioned, there can be rows with 0 values, find the rows which maximum sum of values between two zeros(as we don't need to include rows with 0 values)
Step 4 : If there are no zero rows or only one zero row then find the smallest sum in the map and then you can get the array with maximum one's
Step 5: You can further iterate on the result to remove columns.
Let me know whatever your views are.