## Counting nodes within K distance from set of given nodes in a tree

The question says: Given an undirected tree with some marked nodes and a positive number K. We need to print the count of all such nodes which have distance from all marked nodes less than K which means every node whose distance from all marked nodes is less than K, should be counted in the result.

.The solution mentioned says we find two marked nodes that are at a max distance among all the pairs of marked nodes, and any node which is within k distance from both the nodes will be within k distance from all the marked nodes, and for that they do bfs from “random node” to get first distant marked node and then the second bfs from this found node to get the second distant node. I understood how the second bfs from the first distant node finds other distant node but I am unable to visualize how could a bfs from “random node” in the tree helps to find one of the distant nodes.

## Counting the number of vowels and consonants in a string

I am creating a program that can count the number of vowels and consonants in a string. So far it has only been returning the number of characters in the string as a whole. Could you please tell me what I am doing wrong? Thank you

``import java.util.Scanner; ``

public class LanguageDriver { //your solution must include the practical use of these objects private CharacterCounter cc = new CharacterCounter(“Default phrase.”); private AlphaOnly trans = new AlphaOnly(“Default phrase.”);

``private Scanner scan = new Scanner(System.in);  //this String might be helpful private String vowelStr = "AEIOUaeiou";   //surveys the user for information //controls execution public void userInput() {    System.out.println("Enter a sentence.");    String phrase = scan.nextLine();    cc.setWord(phrase);    trans.setWord(phrase);    int consonants = 0;    int vowels = 0;     for(int i = 0; i < phrase.length(); i++)    {    //checks if the letter at "i" is a vowel        if (phrase.substring(i, i+1) == "a" || phrase.substring(i,i+1) == "e" || phrase.substring(i,i+1) == "i" || phrase.substring(i,i+1) == "o" || phrase.substring(i,i+1) == "u")        {            vowels++;         }         else            {             consonants++;           }      }         System.out.println("There are " + consonants + " consonants " + " and " + vowels + " vowels." ); } ``

}

## How to stop counting point when player dies (Destroy)

In my game, I’d like to stop counting points when the player’s y is -4. When the pink and red balls fall off the Plane the player gets points. But it seems a bit strange to be able to collect points after the player dies.

This is the code for the player:

``     if (transform.position.y < -4)     {        Destroy(gameObject);        gameManager.GameOver();     } ``

And in the GameManager.cs I have this:

``   public bool isGameActive;     public void UpdateScore(int scoreToAdd)    {       score += scoreToAdd;       scoreText.text = "POENG: " + score;    }     public void GameOver()    {       isGameActive = false;       restartButton.gameObject.SetActive(true);       gameOverText.gameObject.SetActive(true);    } ``

And this is the code for adding points when the enemies fall over the edge:

``    if (transform.position.y < -4)     {        Destroy(gameObject);        gameManager.UpdateScore(pointValue);     } ``

How can I make the game stop counting points when the player dies?

## Matrix element value counting in O(1) space

Given an NxM matrix of integer values, we need to verify that the number of non-zero elements in every row and every column is maximum 2. The matrix cannot be stored! It comes as a stream (M and N are known in advance but are not constants), row after row, and each element is accessed only once. The space requirement is O(1), i.e. no additional array of size N or M can be used, only a constant number of variables.

Can this be done? If not, can it be proved? Can this be done in O(log(N) + Log(M)) space?

Thanks allot

## URL Character Counting – Where to start counting?

I’m rewriting URLs for a website, I know it could affect SEO, but I’ve no choice but to rewrite them, and 301 redirect the old ones to their new URLs. I want to try to keep the new URLs short and to the point.

When I’m counting the total number of characters in a URL, I shouldn’t include the protocol `https://` in my character count, right? Should include every character including dots, hyphens, slashes etc, after the initial `https://` or something else? I’m assuming I count characters like I’ll show in an example below, but want to check, please.

``example.com/product/shoes ``

Would count as a total of 25 characters, right?

## Counting Actual Words In SharePoint

I have a SharePoint List (only OTB access)..

I want to count the number of words (omit spaces) in a given cell in my list.

Is there an actual formula that can handle that?

Also, just an addition… is there an effinent way to count the words but omit words that are between parentheses? ex. (No one is home)

## Counting round in two Gale-Shapley Algorithem(Deferred Acceptance Algorithm)

Imagine there is a modified version of many-to-one matching with Deferred Acceptance Algorithm(DAA): other things will be the same as original DAA, except that for an unassigned student, who was rejected in the previous round, will not apply to a school where this school’s seats are full and the tentatively assigned students all have higher priority over this student(which means that the student has no choice to be admitted). Let’s call it Modified DA.

These two mechanisms have exactly the same result since the modified DA just make the process more compact.

My question is: image that in step k of Modified DA, which step in the original DA, should step k in Modified DA corresponds to?

I am asking because I am doing a proof, where I know the step of the modified DA, but I need to count in which step in the Original DA. Thanks a lot for your attention!

## counting comparisons shell sort will use to sort list

How many comparisons will Shell sort use to sort the following list (9, 3, 10, 2, 7, 1, 0, 11, 6, 5, 8, 4) if gaps of 3 then 1 are used?

I have a beginning understanding of how shell sort works, however I am confused how to count the comparisons shell sort will use to sort the list?

## Counting common values in two arrays

given two arrays of integers A and B of size m, with values in the range [-n,n]. I want an algorithm to count how many common values are in A and B , if a value is repeated we only count it once , for example : $$A=\{2,2,14,3\}$$ and $$B=\{1,2,14,14,5\}$$ the algorithm should return 2 . Problem is I need to do this in $$O(m)$$ time.

My attempt was to create an array $$C$$, of size $$2n$$. and increment all the values of $$A$$ and $$B$$ by $$n$$, and count the values of $$A$$ like: $$C[A[i]] = 1$$ that would take me $$O(m)$$ time , and $$O(1)$$ time to create the array. then going over $$B$$ and counting how many $$1’s$$ I encounter in $$C$$.

So far it sounds good, however I have no idea what’s in $$C$$ in the first place and it could be that there’s a $$1$$ in there already and that would increment the counter falsely , and initializing $$C$$ would take $$O(n)$$ time.