Tuesday, February 11, 2025

 There are N points (numbered from 0 to N−1) on a plane. Each point is colored either red ('R') or green ('G'). The K-th point is located at coordinates (X[K], Y[K]) and its color is colors[K]. No point lies on coordinates (0, 0).

We want to draw a circle centered on coordinates (0, 0), such that the number of red points and green points inside the circle is equal. What is the maximum number of points that can lie inside such a circle? Note that it is always possible to draw a circle with no points inside.

Write a function that, given two arrays of integers X, Y and a string colors, returns an integer specifying the maximum number of points inside a circle containing an equal number of red points and green points.

Examples:

1. Given X = [4, 0, 2, −2], Y = [4, 1, 2, −3] and colors = "RGRR", your function should return 2. The circle contains points (0, 1) and (2, 2), but not points (−2, −3) and (4, 4).

class Solution {

    public int solution(int[] X, int[] Y, String colors) {

        // find the maximum

        double max = Double.MIN_VALUE;

        int count = 0;

        for (int i = 0; i < X.length; i++)

        {

            double dist = X[i] * X[i] + Y[i] * Y[i];

            if (dist > max)

            {

                max = dist;

            }

        }

        for (double i = Math.sqrt(max) + 1; i > 0; i -= 0.1)

        {

            int r = 0;

            int g = 0;

            for (int j = 0; j < colors.length(); j++)

            {

                if (Math.sqrt(X[j] * X[j] + Y[j] * Y[j]) > i)

                {

                    continue;

                }

                if (colors.substring(j, j+1).equals("R")) {

                    r++;

                }

                else {

                    g++;

                }

            }

            if ( r == g && r > 0) {

                int min = r * 2;

                if (min > count)

                {

                    count = min;

                }

            }

        }

        return count;

    }

}

Compilation successful.

Example test: ([4, 0, 2, -2], [4, 1, 2, -3], 'RGRR')

OK

Example test: ([1, 1, -1, -1], [1, -1, 1, -1], 'RGRG')

OK

Example test: ([1, 0, 0], [0, 1, -1], 'GGR')

OK

Example test: ([5, -5, 5], [1, -1, -3], 'GRG')

OK

Example test: ([3000, -3000, 4100, -4100, -3000], [5000, -5000, 4100, -4100, 5000], 'RRGRG')

OK


Monday, February 10, 2025

 A previous article described the formation of a UAV swarm when aligning to a point, line and plane. While the shape formations in these cases are known, the size depends on the number of units in the formation, the minimum distance between units, the presence of external infringements and constraints and the margin required to maintain from such constraints. The article also described the ability to distribute drones to spread as close to the constraints using self-organizing maps which is essentially drawing each unit to the nearest real-world element that imposes a constraint. This establishes the maximum boundaries for the space that the UAV swarm occupies with the core being provided by the point, line, or plane that the units must align to. Given the minimum-maximum combination and the various thresholds for the factors cited, the size of the shape for the UAV swarm at a point of time can be determined.

This article argues that the vectorization, clustering and model does not just apply to the UAV swarm formation in space but also applies to maintaining a balance between constraints and sizing and determining the quality of the formation, using Vector-Search-as-a-judge. The idea is borrowed from LLM-as-a-judge which helps to constantly evaluate and monitor many AI applications of various LLMs used for specific domains including Retrieval Augmented Generation aka RAG based chatbots. By virtue of automated evaluation with over 80% agreement on human judgements and a simple 1 to 5 grading scale, the balance between constraints and sizing can be consistently evaluated and even enforced. It may not be at par with human grading and might require several auto-evaluation samples but these can be conducted virtually without any actual flights of UAV swarms. A good choice of hyperparameters is sufficient to ensure reproducibility, single-answer grading, and reasoning about the grading process. Emitting the metrics for correctness, comprehensiveness and readability is sufficient in this regard. The overall workflow for this judge is also similar to the self-organizing map in terms of data preparation, indexing relevant data, and information retrieval.

As with all AI models, it is important to ensure AI safety and security to include a diverse set of data and to leverage the proper separation of the read-write and read-only accesses needed between the model and the judge. Use of a feedback loop to emit the gradings as telemetry and its inclusion into the feedback loop for the model when deciding on the formation shape and size, albeit optional, can ensure the parameters of remaining under the constraints imposed is always met.

The shape and size of the UAV formation is deterministic at a point of time but how it changes over time depends on the selection of waypoints between source and destination as well as the duration permitted for the swarm to move collectively or stream through and regroup at the waypoint. A smooth trajectory was formed between the waypoints and each unit could adhere to the trajectory by tolerating formation variations.

Perhaps, the biggest contribution of the vectorization of all constraints in a landscape is that a selection of waypoints offering the least resistance for the UAV swarm to keep its shape and size to pass through can be determined by an inverse metric to the one that was used for self-organizing maps.


Sunday, February 9, 2025

 #codingexercise 

Merge two BSTs 

One method to do this is to use two auxiliary stacks for two BSTs.  If we get a element smaller from the trees, we print it. If the element is greater, we push it to the stack for the next iteration. 

We use the iterative inorder traversal :  

  • Create an empty stack S 

  • Initialize current node as root 

  • Push the current node to stack S, set current to current.left, until current is NULL 

  • If the current is null and stack is not empty then 

  • Pop the top item from stack 

  • Print the popped item 

  • Set current = popped_item.right 

  • Goto step 3 

  • If current is null and the stack is empty, then we are done. 

To merge the BST we do the following: 

Initialize two stacks s1 and s2 from null. 

If the first tree is null, do iterative inorder traversal of second to print the merge 

If the second tree is null, do iterative inorder traversal of first to print the merge 

Set current in tree 1 to be cur1 and current in tree 2 to be cur2 

While either cur1 or cur 2 is not null or  one of the stacks is not empty: 

  • If cur 1 or cur 2 is not null 

  • For both the tree, if the current is not null, push it onto the stack, set current to current.left This will be repeated by the while until current is nul is null 

  • Else 

  • If either of the stacks is empty, then one tree is exhausted, print the other tree.  Do this for both stacks. 

  • Set the current of each tree to the popped element from respective tree 

  • Compare the two current and execute an iteration of step3 from iterative inorder traversal above  - the smaller of the two current nodes is printed, the larger pushed back on its corresponding stack 

At the end of the while loop, both stacks should be empty and the currents must be pointing to null and both the trees would be printed. 


#CODINGEXERCISE: CodingExercise-02-09-2025.docx

Saturday, February 8, 2025

 

This is a summary of the book titled “Project Management Step-by-Step: How to plan and manage a highly successful project” written by Richard Newton and published by Pearson Business in 2024. The author reminds readers that a project is an undertaking with clear endpoint and while it can be as small as cooking for a dinner party to as big as launching a business, he advises on how to get it done on time and on budget. The skill is both significant and worthwhile for people starting out on their professional journey and comes in all-the-handier as projects grow in size and complexity. Projects emerge in stages and with multiple dimensions including scope, quality and risk. Someone with this skill should know everything that the project seeks to achieve. So, working backwards from the objective and coming up with a clear project definition and project plan is helpful. Continuously monitoring the progress at every stage of the project, and completing the fit and finish at the end are good practice. Stakeholders and customers must be made aware of the deliverables and the project manager must remain flexible in how to get there.

Project management is essential for those starting professional careers, as it involves a series of stages and multiple dimensions, including scope, quality, and risk. A specialized approach is necessary for complex projects, such as launching a rocket or a company. Projects typically go through at least five stages: Project Definition, Project Plan, Execution, Checking Deliverables, and Closing Down. A project manager must state the project's scope and target, work with their team to fulfill goals, and determine acceptable risk levels. They must also understand standard details like completion time, staff and materials requirements, and costs. A specialized approach is necessary for complex projects with high stakes, as countless details can go wrong.

Project managers must understand the purpose and goals of their projects to ensure successful completion within financial and time constraints. They should ask simple, structured questions to understand the project's "why" and "what." They should also consider potential conflicts with other ongoing projects and potential stumbling blocks. Client-driven constraints like time and budget should be considered, and a broader definition should be agreed upon. Project managers must communicate with clients to ensure they understand the potential implications of changing plans.

A clear Project Definition and Project Plan are essential for project managers, outlining the project's purpose, responsibilities, and potential timelines. A Project Plan outlines the necessary work, tasks, and resources needed to complete the project. Estimating the time each task takes is a challenging aspect of formulating a project plan, but it is essential to estimate the time each task typically absorbs. Consultation with experienced individuals or comparing tasks with existing time frames can help clarify the process.

Project managers must stay actively involved throughout a project's life cycle to ensure it is completed on time and on budget. A solid Project Plan should allocate resources and provide leadership to move the project forward. A project manager's primary daily task is to manage and measure progress according to the Project Plan. Regularly assess progress, monitor budget allocation, and anticipate repercussions of running over budget.

Successful projects end with all loose ends tied up, and the Project Plan should include completion time, details, and expenses. The project manager is responsible for the project's final deliverables, and they must test them themselves to ensure they function as expected and meet the client's needs.

After completing a project, continue to support the client and stay updated on how the current project operates to learn how to perform even better on the next project.

To ensure customer satisfaction and high-quality standards, it is essential to test and integrate deliverables. Integration is a separate task that requires time and resources and should be included in the project plan. It is crucial to line up with people who can handle the integration process. Once the deliverables are complete, they need to function in the project's targeted environment. Change management issues must be addressed, and employees must be trained to demonstrate that the new deliverables will work for them. Project management is dynamic, and quality managers should stay open to alternative approaches. Agile project management, for example, focuses on experimentation and continuous improvement. A daily stand-up is a common practice in many organizations, where team members report on their progress, plans, and challenges. This helps team members help each other in a timely manner, leading to a productive agile project team.

#Codingexercise: tilesandfloor.docx

Friday, February 7, 2025

 This is a summary of the book titled “From pessimism to promise” written by Payal Arora and published by MIT Press in 2024. The author is a digital anthropologist who reconciles diverse take on the digital future where the Global South are eager for it and the West is mostly apprehensive. Western policymakers are focused on breaking up large tech companies and regulate AI and social media. She contends that AI design should focus on relationships and how people can develop technology for positive ends. She asks us to imagine the possibilities of a creative economy that engages young people, especially when these technologies encourage pleasure and intimacy. It can be used for surveillance in a police state but can also be used to care for others. And it could support a green economy. In fact, AI cannot stand apart from the physical multicultural world. We must just design AI such that it avoids the Global South’s colonial past.

Western users have negative attitudes towards digital technologies, viewing platforms as traps and algorithms as manipulative. This has led to a "pessimism paralysis" where Westerners are more likely to accept the status quo than try to change it. However, young people in the Global South, including China and India, see digital culture as a source of joy, inspiration, and liberation. Nearly 90% of youth worldwide live in the Global South, and they are optimistic about the future and eager to use digital platforms to change their lives and the world. AI design should focus on relationships and how people can develop technology for positive ends, rather than grandiose plans to "save the world." Tech designers should focus on the relationships between real people, concrete circumstances, and actionable policies, rather than looking at things in black-and-white or binary ways. The real world is messy, and technology that will benefit humans in their daily lives requires designing with the on-the-ground contexts and experiences of users in mind.

The concept of the "creative class" has evolved, with the next big movement in digital culture and the creative economy likely coming from the tens of millions of young people in the Global South. These young people, weighed down by social and political pressures, are eager to define their digital futures and are looking to their people as creative assets, legitimate markets, and content partners. Social media apps like TikTok and Bigo have thrived in the Global South due to their focus on the poor and marginalized, allowing them to gain greater visibility and engage in the creative economy.

Digital technologies should be designed to encourage pleasure and intimacy, as 35% of internet downloads are connected to pornography, with one-third of the porn-viewing audience being women. In countries where open discussion of sex and sexuality is taboo, young people often turn to digital pornography as a form of sex education. Countries in the Global South, like India, are proactive in controlling access to online sexual content, but NGOs have embraced social media campaigns and apps to broaden access to sex education.

Digital innovators are exploring ways for young people to build ties online that prioritize romance and relationships over sex. Platforms like Soulgate and FRND aim to create an open, pleasurable, and safe environment for young people to connect. Digital technologies can be used for surveillance in a police state, but they can also be used to care for others. A surveillance system of care that moves away from watching each other as a form of policing to watching over one another as a form of recognition and compassion is needed to rebuild social trust.

Design AI in ways that support a green economy is crucial for promoting environmental and social goals. Over half of a product's environmental impact is shaped by decisions made at the design phase. Indigenous communities in the Global South have developed four categories of design approaches: frugality, collectivity, subsistence, and repair. These approaches focus on reimagining power relations, valuing diversity, and repurposing existing structures.

AI cannot stand apart from the physical, multicultural world, as it is a human activity that is incorporated into people's lives. To promote sustainable, green design, it is essential to evaluate the material costs of incorporating AI and digital automation into human life. The digital future must promote the health of the environment and human societies, and companies, entrepreneurs, and designers must adopt a multicultural and multilingual approach.

AI design must move past the colonial past and "decolonize" AI and its datasets and algorithms. Businesses and institutions must not only state moral and political principles but also work towards a more inclusive and equitable digital culture.


Thursday, February 6, 2025

 Air-borne UAV swarm prefers formation in many cases. There are several factors that play into this but primarily a formation ensures all fleet units go through the waypoints with minimal overhead and computation as long as constraints permit. They reach a common objective together and complete the main mission in the most energy efficient manner and with high throughput. Formation also provides mutual protection, enhanced defense and support against threats. Communication and co-ordination, although not cheap, ensures that all units are easily accounted for and their telemetry indicates continuous progress for everyone. There is efficient use of resources like fuel or battery power and some of the drones internal to the formation can conserve their sensors.

Conversely, when they break up it is most likely that no size for the formation is tolerated by the constraints of the landscape. For example, flying under a bridge with an absolute restriction on the height forces the formation to fly one-by-one through the space under the bridge. The transformation from the formation to a queue of solo flying units and subsequent regrouping can be both easy and smooth in anticipation of the constraint and its subsequent relaxation after the constraint is overcome. These tactical manoeuvres are part of the constraints and thresholds based decisions. Similarly, splitting of a few units from the formation to parallelize the throughput across multiple arches of bridges is also possible just as much as wind and weather conditions might dictate making it safe to fly one unit at a time through one arch. The overall adherence to the trajectory is not sacrificed and the splitting of a fraction of the UAV swarm provides more sensor information via scouting. Equipment malfunctions also might cause the units to break from formation and regroup when permissible.

A previous article described the formation of a UAV swarm when aligning to a point, line and plane. While the shape formations in these cases are known, the size depends on the number of units in the formation, the minimum distance between units, the presence of external infringements and constraints and the margin required to maintain from such constraints. The article also described the ability to distribute drones to spread as close to the constraints using self-organizing maps which is essentially drawing each unit to the nearest real-world element that imposes a constraint. This establishes the maximum boundaries for the space that the UAV swarm occupies with the core being provided by the point, line, or plane that the units must align to. Given the minimum-maximum combination and the various thresholds for the factors cited, the size of the shape for the UAV swarm at a point of time can be determined.

#Codingexercise: Codingexercise-02-06-2025

Wednesday, February 5, 2025

Friends of appropriate ages:

There are n persons on a social media website. You are given an integer array ages where ages[i] is the age of the ith person.

A Person x will not send a friend request to a person y (x != y) if any of the following conditions is true:

• age[y] <= 0.5 * age[x] + 7

• age[y] > age[x]

• age[y] > 100 && age[x] < 100

Otherwise, x will send a friend request to y.

Note that if x sends a request to y, y will not necessarily send a request to x. Also, a person will not send a friend request to themself.

Return the total number of friend requests made.

Example 1:

Input: ages = [16,16]

Output: 2

Explanation: 2 people friend request each other.

Example 2:

Input: ages = [16,17,18]

Output: 2

Explanation: Friend requests are made 17 -> 16, 18 -> 17.

Example 3:

Input: ages = [20,30,100,110,120]

Output: 3

Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.

Constraints:

• n == ages.length

• 1 <= n <= 2 * 104

• 1 <= ages[i] <= 120

class Solution {

    public int numFriendRequests(int[] ages) {

        int[][] requests = new int[ages.length][ages.length];

        for (int i = 0; i < ages.length; i++) {

            for (int j = 0; j < ages.length; j++){

                requests[i][j] = 0;

            }

        }

        int sum = 0;

        for (int i = 0; i < ages.length; i++) {

            for (int j = 0; j < ages.length; j++){

                if (i == j) continue;

                if (ages[j] <= 0.5 * ages[i] + 7) continue;

                if (ages[j] > ages[i]) continue;

                if (ages[j] > 100 && ages[i] < 100) continue;

                requests[i][j] = 1;

                sum += 1;

            }

        }

        return sum;

    }

}