473,513 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Longest sub array in rotating array

1 New Member
Guys is there any way to find the longest subarray of 1's in log(n) time.

example

1- 110011111000 then the output is 5 from pos 5 to 10

2- 1110011101 the output here is 3 but after rotation 1 the array becomes

111100111 and the output is now 4.

3 - 001111 the output here is 4 from pos 3 to 6 but after rotation it becomes 3 from pos 4 to 6

Note: i found the longest subarray length in O(n) before rotation ... how can i improve the solution after rotation if i have the past results..
Nov 11 '18 #1
1 3946
Rabbit
12,516 Recognized Expert Moderator MVP
This is a weird question. Is this homework?

You can still do this in O(n). Just need a few extra variables. One for the length of the starting block. And one for the ending block that updates for each found block until you reach the end. Then you just need to check the last character to see if you need to subtract one from the end and add one to the start.
Nov 13 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2180
by: Bob Bedford | last post by:
I've this structure in a XML file: Type Model Detail Datas Datas Datas Datas /Detail Detail
1
1532
by: Bob Bedford | last post by:
Still having problem with array of arrays. Here is the code: echo("Name: ".$res."<br>"); //$res is an array with many MODELNAME while(list($k,$v) = each($res)){ echo("Name: ".$res."<br>"); While the first line (the echo) works fine, the echo in the "while" doesn't work.
12
10592
by: JKop | last post by:
template<class T> inline T& NthArrayMember( T & (array),size_t i) { return array; } template<class T> inline const T& NthArrayMember( const T & (array),size_t i) { return array;
20
78037
by: Geoff Cox | last post by:
Hello, This may be the answer to a problem I have - or it may not be possible?! Can I have initial values of variable situation and count defined as var situation = 0; var count = 0;
8
2487
by: kings_oz | last post by:
I have an array or items each item in the array can contain another array of other items and that array of other items can contain more array of item. I want recursively iterate through the array and print out all the items. Can anyone show me some light. Thanks in advance.
7
4394
by: Eric Boutin | last post by:
Hi ! I would like to generate an array of type char; I just dont really figure out how I could do it with malloc or calloc.. I mean.. I know how to allocate a simple array with both of them; but when it comes to a 2 dimension array.. I'm stuck.. I mean.. if I ask for char** array = malloc(5*n*sizeof(char));, it'll return a void*, not a...
10
12183
by: Steve | last post by:
this code: private Array m_arrays = new Array; results in an array of 3 null Array objects. What am I missing?
2
1717
by: Kenneth Brody | last post by:
Given the following current definition: int array; Is the following equivalent? (By "equivalent", I mean that any reference to "array" retains the same meaning, and that the memory layout of the 200 ints is identical.)
8
15002
by: =?big5?B?r0W84Q==?= | last post by:
Hi All C gurus: Below is a small program to print out the address of array and address of array variable: int main() { char array = "haha"; printf("array:%x\n", array); printf("&array:%x\n", &array); }
4
2876
by: Bob Bedford | last post by:
Hello, I've an array of array(1,2,3,4). I'd like to retrieve the values in 3 and 4 giving the values 1 and 2. How can I do that, how to search in an array of array ? in short, how to write the findvalue function ? $list = array(); array_push($list,array(1,1,'x','x'); array_push($list,array(1,2,'x','y');...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.