Wednesday, July 17, 2024

 Problem Statement: Given an integer array arr, in one move you can select a palindromic subsequence arr[i], ..., arr[j] where 0 <= i <= j < arr.length, and remove that subsequence from the given array. Note that after removing a subarray, the elements move to remove the gap between them.

 

Return the minimum number of moves needed to remove all numbers from the array.

 

Solution:

import java.util.*;

class Solution {

    public int minimumMoves(int[] arr) {

        int N = arr.length;

        int max = 1;

        int min = Integer.MAX_VALUE;

        List<Integer> A = new ArrayList<>();

        for (int i = 0; i < arr.length; i++) A.add(arr[i]);

        int count = 0;

        while(A.size() > 0) {

           boolean hasPalindrome = false; 

           List<Integer> elements = new ArrayList<>();

           for (int i = 0; i < (1<<N); i++) { 

               

               List<Integer> combination = new ArrayList<>(); 

                for (int j = 0; j < A.size(); j++) { 

                  if ((i & (1 << j)) > 0) { 

                    combination.add(j); 

                  } 

                } 

                if (isPalindrome(A, combination) && (combination.size() > max) && getCharactersToRemove(A, combination) < min) {

                      hasPalindrome = true;

                      max = combination.size();

                      min = getCharactersToRemove(A, combination);

                      elements = new ArrayList<>(combination);                

                      if (getCharactersToRemove(A, combination) == 0) { break;}

                } else {

                    // System.out.println("A: " + print(A) + " Elements: " + print(elements) + " Combination: " + print(combination) + "isPalindrome=" + String.valueOf(isPalindrome(A, combination)) + " getCharsToRemove=" + getCharactersToRemove(A, combination) + " min = " + min);

                }

           }            

           if (!hasPalindrome) {

               count += 1;

               A.remove(A.size() - 1);

           } else {

               count += getCharactersToRemove(A, elements) + 1;

               A = removeCharacters(A, elements);

               // System.out.println("Removing " + count + " characters at indices:" + print(elements) + " and remaining elements: " + print(A));

               // elements = new ArrayList<>();

               max = 1;

               min = Integer.MAX_VALUE;

           }

        }

        return count;

    }

    public boolean isPalindrome(List<Integer> A, List<Integer> combination) {

        int start = 0;

        int end = combination.size()-1;

        while (start <= end) {

            if (A.get(combination.get(start)) != A.get(combination.get(end))) {

                return false;

            }

            start++;

            end--;

        }

        return true;

    }

    public int getCharactersToRemove(List<Integer> A, List<Integer> combination){

        if (combination.size() < 2) return 0;

        List<Integer> clone = new ArrayList<>(A); 

        return removeCharacters(clone, combination).size();

    }

    public List<Integer> removeCharacters(List<Integer> A, List<Integer> combination) {

     int start = 0;

     int end = combinations.size()-1;

     int last = 0;

     while (start <= end) {

             for (int i = last; i< A.size(); i++) {

                    if (A.get(i) == combination.get(start)) {

                          A.set(I, Integer.MAX_VALUE);

                          last = i+1;

                          start++;

                    }

             }

     }

    List<Integer> result = new ArrayList<>();

    For (int I = 0; I < A.size(); i++) {

         if (A.get(i) != Integer.MAX_VALUE) {

               result.add(A.get(i));

          }

    }

    return result;

    }

    public List<Integer> removeCharacters(List<Integer> A, List<Integer> combination) {

        int start = combination.get(0);

        int end = combination.get(combination.size()-1);

        List<Integer> result = new ArrayList<>();

        if (start > 0){

            result.addAll(A.subList(0, start));

        }

        if (end < A.size() - 1) {

            result.addAll(A.subList(end + 1,A.size()));

        }

        return result;

    }

    public String print(List<Integer> elements){

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < elements.size(); i++) {

            sb.append(elements.get(i) + " ");

        }

        return sb.toString();

    }

}


Examples:

A = [-1,0,1]           => 3

A = [-1,0,-1]          => 1

A = [-1]                    => 1

A = [-1,0]                => 2

A = [0,0]                 => 1

A = [1,0,1,2,3]     => 3

A = [-2,-1,0,1,0]   => 3


Tuesday, July 16, 2024

 These are more use cases targeted for a commercial drone fleet management software that scales elastically and helps drones manage their flight path in real-time.

Case 8: Safety enforcement on failures across multiple drone units is a scenario that should not be the norm, but it is dedicated to the platform for its capability to operate different fleets. Take the specific example of 55 drone units failing out of 200 for a 4th of July show where the failed units landed in Angle Lake close to SeaTac airport and sank to the bottom, some with their lights on. It was a technical glitch where multiple airborne units failed with “no global positioning” and instead of falling from the sky, made controlled landings into the lake. If there were an override to the GPS failure, it could have resulted in runaways, injury or damage. Each of the drones cost about $2600 to the Great Lakes Drone Co based out of Coloma, Michigan before they engaged in safety policies, procedures and programming to make controlled landings.  External interference such as radio deterrence devices including radio frequency jammers or internal malfunctions such as system compromise were not ruled out. The point of this use case is that the responsibility for the flight of the drones lies not just with the controller but also with the platform relaying commands to the drones. Such a use case that spans all drone fleets and their formations and flight paths across tenants is a specific use case that must be tried out with drills and controlled environments. Some amount of Chaos Engineering practices apply to the handling of these drones via the portal.

Case 9: One of the benefits of a cloud native platform for drone fleet management is that this pseudo resource can make use of other user-friendly services such as OpenAI for chatbot like interaction with the software, Cognitive services for multi-media analysis from drone captures, and for voice translation into commands for the drone fleet. From mundane tasks of using a data lake to stash all sensor captures from the drone fleet organized by individual drones as folders and with data plane access separate from control plane access, to more advanced and sophisticated use cases of correlating and automation service requests against drone fleet inventory and dynamic control of fleet crew, the possibilities are endless. Even workflow management becomes easier with cloud resources and integration. Customized automations are facilitated by the cloud’s powerful methods of interactions namely api, sdk, command line and portal.

Previous use cases: DFCSUseCasesList.docx : https://1drv.ms/w/s!Ashlm-Nw-wnWhPB1Ov2NRhBtAQFyNQ?e=GhfAMw

References: https://1drv.ms/w/s!Ashlm-Nw-wnWhPA9saJLYQGA7q2Wiw?e=AONTxo for data architecture 

https://1drv.ms/w/s!Ashlm-Nw-wnWhO4OGADjCj0GVLyFTA?e=UGMEpB for software description.


Monday, July 15, 2024

 Drone Data Architecture:

One of the advantages of a cloud platform for real-time drone data capture and analysis is that the businesses who sign up for it do not have to reinvent it for themselves. In fact, the cloud data architecture, deployment and data driven applications can be stood up with full IaC and data seeding without even involving any drones. When this proof-of-concept has succeeded, scaled, performed and optimized for lowest cost, it is a veritable proprietary patentable asset and one that can serve the world for various use cases. As of today, just a little bit over 10% of enterprises, enact data strategy that works. Drone data a niche but any investments in its planning and architecture will win over mindshare that can only grow. Data is regarded as a byproduct of operations but it can become a driver of business value. With that comes many choices for data infrastructure and tools in a vast ecosystem. Cloud continues to dominate this space with ever increasing storage and computing power to crunch the data. With drone data, the options for being tied down with legacy or on-premises silos just do not exist, so there is an opportunity to start right. Some consider data architecture to be an oxymoron because databases, data warehouses and data lake do not eliminate one another and evolve their own architectures, so that is again an opportunity to start right for drone data without complexity and even come with full-service in the foreseeable increase in regulatory requirements on drone data. Data democratization will favor data literacy which in turn will foster data culture. Also, this builds a single source of truth with purview and that matters.

The previous articles regarding storage of Drone Data enumerated the following components or lines of data organization for workloads such as business analytics, data engineering, streaming and Machine Learning:

Traditional databases for inventory including progressive states and timestamps along with drone capabilities such as degrees of freedom which is inherently relational 

Vector database for training and inferences for both self-organizing maps and CNNs

Performance databases leveraging embedded, unstructured, QoS and cloud databases

Graph databases to serve graph analytics between drones 

Cache infrastructure to mitigate the load on the data tier 

Streaming Data services such as Apache Flink Live and others.

Leaving out the microservices, apis, UI, scriptability and analytics stacks out of the data access discussion and in this section, we describe the workloads in terms of updates and search. This data architecture drawn out from the previous articles strives to drive the most relevant, real-time application experience supporting data acquisition, metadata filtering and the highest F-score search results. A single query must be responded to using vector search, text search, and metadata filtering and consequently span multiple data sources which may not have been virtualized or made amenable to a single SQL-like query interface. While vector embeddings use large language models are becoming popular on the web and cloud computing, model for drones is subject to more specific domain data and filters and draws from the interdisciplinary science from traffic engineering, computer networks, pattern recognition and database systems. This translates to the following requirements:

Fast complex search – spanning vectors, txt, geo and custom json data

Data and index changes – spanning large number of vectors

Rankings – from various ranking algorithms

Real-time and historical updates – with ability to update and delete any data including vectors in milliseconds without incurring reindexing costs

Hyperconverged indexing that includes different types of indexes such as vector index, range index, column store and documents will be sought-after for this kind of platform to manage drone fleet.

#codingexercise: CodingExercise-07-15-2024.docx


Sunday, July 14, 2024

 Drone:

- SysId

- ID

- Name

- Status

- Created

- Modified

- CreatedBy

- ModifiedBy

- Degree-of-freedom

- Max speed

- FuelType

- BatteryLife

- NumberOfFans

- FanStatus1-8

- Location

- Weight

- PayloadWeight

- Mileage

- Color

- LightSensor

- HeatSensor

- IRSensor

- Camera

- Zoom

- Pitch

- Yaw

- Roll

- Display0-255

Fleet:

- ID

- Name

- Drones

- Created

- Modified

- CreatedBy

- ModifiedBy

Location

- Geo coordinates

- GPS Tracking

- LastUpdated

-


Friday, July 12, 2024

 These are more use cases targeted for a commercial drone fleet management software that scales elastically and helps drones manage their flight path in real-time.

Case 6: So far the use cases have elaborated conveniences for drone makers, fleet operators, businesses leveraging drone for delivery, but the following use case focuses on end-users. A drone unit and a small personal fleet of drones can come in helpful for individuals such as farmers or for home security where the units fly to take aerial photo/video around a specific landmark such as a home or barn. Today a single drone is sold along with its remote-operated controller for manual flying but a small fleet of drones can also be sold if they are registered with and controlled by cloud software for specific limited activities. The end-user may download an application and scan the qrcodes off the back of drones so that the application registers them with the clouds and is able to relay commands individually to them. Then a set of predetermined algorithms can help navigate the  drones for aerial surveillance and footage. They can be launched on ad hoc basis or scheduled periodically and matched with image recognition for durations when active monitoring might help. With the potential to build different models of drones for different range and speed and the possibility to scale up the number of drones in the fleet seamlessly, this software could meet a variety of usages across sectors such as fire and rescue, pet surveillance, pest control, improved security, and many more that do not fall under the small-and-medium business category and enterprise category of use cases mentioned earlier.  With topologies that allow dedicated controller for a fleet of lightweight drones and the controller receiving input from the cloud software and relaying to the drones while sending back the sensor data from the drones, the entire compute, storage and network available from the cloud can be leveraged to overcome the limitations on what is shipped out-of-box today or enhance existing fleet of popular appliances like vacuum robots. A high volume of sensor data traffic over the internet might be considered slow for response times in near real-time to drones but they are more for guidance or changes to schedule so-to-speak for mundane activities in these limited scopes for drones. The cloud is uniquely positioned to scale up to the demands of real-time traffic.

Case 7: Federal Regulatory Compliance and Governance of drone usages and activities across tenants is a specific use case dedicated to this platform and one that can be alleviated from the responsibilities of the businesses signing up as tenants. The platform is uniquely positioned to provide a full data purview including genealogy, history, archival and auditing of every operation associated with the drones registered with the platform. Information as requested and required to be disclosed based on sub-poena sent by law enforcement agencies are easy to be drafted and responded to by the platform. For the businesses themselves, change data capture of the drone data as well as real-time information from logs and metrics stores are something that they can view for themselves and thus enforce necessary role-based access controls and auditing for their requirements on governance.

Previous use cases: DFCSUseCasesList.docx 


Thursday, July 11, 2024

 These are more use cases targeted for a commercial drone fleet management software that scales elastically and helps drones manage their flight path in real-time.

Case 5: Fleet operators looking to serve various businesses want to leverage a common platform for management and operations of their fleet.  Earlier, controllers were assigned to partitioned fleets and the logistics would be dependent on each with isolation provided between controllers. As a multitenant platform, both isolation and scalability are no longer restricted for the customers of this Drone Formation Commercial software. The fleet operators can add as many tenants as they can accommodate, and it is easy to roll inventory from one tenant to another. Decisions taken for the operation of the fleet are not only captured in the same single pane of glass for management but also the outcomes are easy to roll up in consolidated reports from the platform while maintaining drill down on authorized queries. 

Case 6: So far the use cases have elaborated conveniences for drone makers, fleet operators, businesses leveraging drone for delivery, but the following use case focuses on end-users. A drone unit and a small personal fleet of drones can come in helpful for individuals such as farmers or for home security where the units fly to take aerial photo/video around a specific landmark such as a home or barn. Today a single drone is sold along with its remote-operated controller for manual flying but a small fleet of drones can also be sold if they are registered with and controlled by cloud software for specific limited activities. The end-user may download an application and scan the qrcodes off the back of drones so that the application registers them with the clouds and is able to relay commands individually to them. Then a set of predetermined algorithms can help navigate the  drones for aerial surveillance and footage. They can be launched on ad hoc basis or scheduled periodically and matched with image recognition for durations when active monitoring might help. With the potential to build different models of drones for different range and speed and the possibility to scale up the number of drones in the fleet seamlessly, this software could meet a variety of usages across sectors such as fire and rescue, pet surveillance, pest control, improved security, and many more that do not fall under the small-and-medium business category and enterprise category of use cases mentioned earlier.  With topologies that allow dedicated controller for a fleet of lightweight drones and the controller receiving input from the cloud software and relaying to the drones while sending back the sensor data from the drones, the entire compute, storage and network available from the cloud can be leveraged to overcome the limitations on what is shipped out-of-box today or enhance existing fleet of popular appliances like vacuum robots. A high volume of sensor data traffic over the internet might be considered slow for response times in near real-time to drones but they are more for guidance or changes to schedule so-to-speak for mundane activities in these limited scopes for drones. The cloud is uniquely positioned to scale up to the demands of real-time traffic.


Wednesday, July 10, 2024

 These are more use cases targeted for a commercial drone fleet management software that scales elastically and helps drones manage their flight path in real-time.

Case 4: As drone manufacturers make incredible progress in the scope and purpose of drone activities, they would like to outsource software targeting repeated drills across models and versions of their drones including abilities to plugin customizations for enhanced intelligence. These drone manufacturers are experimenting with a variety of shapes, compositions and degrees of freedom both individually and collectively for formations and their ability to overcome obstacles. A cloud software that can be reached ubiquitously by drones themselves or relayers will be cost-effective in maximizing the output of these drones. Among the features expected by the manufacturers are ability to repeat tests, maintain test history,  and generate test reports. A single transparent pane of glass for observability and manageability of the drones along with these reports and dashboards will be very helpful to them for updating their drones.  Initially the size of the fleets for most of these manufactures might be small in research and development but their deployments on their customer premises could be large and require dial-home capabilities from the units or their controllers and relayers. Different kinds of topology involving different types of units participating in overall fleet management and formations must be supported by this software.

Case 5: Fleet operators looking to serve various businesses want to leverage a common platform for management and operations of their fleet.  Earlier, controllers were assigned to partitioned fleets and the logistics would be dependent on each with isolation provided between controllers. As a multitenant platform, both isolation and scalability are no longer restricted for the customers of this Drone Formation Commercial software. The fleet operators can add as many tenants as they can accommodate and it is easy to roll inventory from one tenant to another. Decisions taken for the operation of the fleet are not only captured in the same single pane of glass for management but also the outcomes are easy to roll up in consolidated reports from the platform while maintaining drill down on authorized queries.