Theprogrammersfirst
A technical portal. It contains well explained topics and articles.
Home
Tutorials
Java
Data Structure
Algorithm
Interview Questions
Ask Question
Discussion
About Us
2016-08-06
Write a Programs to Generate Maximum non-empty subarray of an array
Given Array
A
of size
N
find those non-empty subarrays (sequence of consecutive elements)
Sample:
Array [
1 ,1 ,3
]
Output:
1
1
3
1 1
1 3
1 1 3
Solution:
class TestClass {
public static void main(String args[] ) throws Exception {
int arr[] = {1 ,1 3};
subArray();
}
public static void subArray(int arr[], int n)
{
for (int i=0; i <n; i++)
{
for (int j=i; j<n; j++)
{
for (int k=i; k<=j; k++){
System.out.println(arr[k]);
}
System.out.println();
}
}
}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment