Skip to content

Commit

Permalink
initiate orbitax
Browse files Browse the repository at this point in the history
  • Loading branch information
TamimEhsan committed Sep 7, 2024
1 parent 3e04634 commit 49c3a73
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ Stick to the following format to add a question under a company:
</details>
```
Example:
```
<details>
<summary>
What is 1+1?
</summary>
<hr>
1+1 equals 3
</details>

```


## Before submitting the pull request
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default defineConfig({
{text: 'IQVIA', link: '/iqvia'},
{text: 'Priyo', link: '/priyo'},
{text: 'Kite Games Studio', link: '/kite'},
{text: 'Orbitax', link: '/orbitax'},
{text: 'Relisource', link: '/relisource'},
{text: 'Spectrum', link: '/spectrum'},
{text: 'SRBD', link: '/srbd'},
Expand Down
89 changes: 89 additions & 0 deletions docs/orbitax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Orbitax Bangladesh Limited

## Coding Round Questions
<details>
<summary>
You are given an HTML string. Your task is to determine the number of characters encompassed by each HTML tag in the string. For each tag, count the number of characters that are enclosed between the opening (<tag>) and closing (</tag>) tags.

A tag is composed of one or more lowercase English letters (a-z). For example: `<div> ... </div>`, `<span>..</span>`. It can be followed by digits (0-9) i.e `<h1>..</h1>`.

The content between the tags can consist of:
1. English characters (a-z, A-Z).
2. Digits (0-9).
3. Punctuation marks: period (.), comma (,), and spaces(' ').

Note:
When a character is encompassed by a same tag multiple times, count only once for that tag.
A tag can have 0 characters. In that case don't print that tag.
Spaces(' ') between the tags are not counted.

</summary>
<hr>

[**💻 Submit Code**](https://www.hackerrank.com/contests/orbitax-associate-software-engineer-recruitment-2024-phase-1/challenges/count-between-tags/problem)

```C++
string consume(string &s,int st){
string tag;
while(s[st]!='>') tag+=s[st++];
return tag;
}

void solve(string s) {
// the total character inside a tag
map<string,int> totalCharCount;
// to find the nesting level of a tag
// eg. <p><p></p></p>, here p is nested two times
map<string,int> nestedTagLevel;

vector<string> tags;
vector<int> charCount;

// signifies root level tag
// helps to simplify code logic
tags.push_back("");
charCount.push_back(0);

for(int i=0;i<s.size();i++){
if( s[i] == '<' and s[i+1]!='/' ){
// starting tag
string tag = consume(s,i+1);
// advance pointer by the consumer
// character count
i+=tag.size()+1;
tags.push_back(tag);
charCount.push_back(0);
nestedTagLevel[tag]++;
}else if( s[i] == '<' and s[i+1] == '/' ){
// ending tag
string tag = consume(s,i+2);
// advance pointer by the consumer
// character count
i+=tag.size()+2;
int cnt = charCount.back();
nestedTagLevel[tag]--;

// increment count only if it has no parent
// tag of same type
if( nestedTagLevel[tag] == 0 ){
totalCharCount[tags.back()] += cnt;
}
charCount.pop_back();
tags.pop_back();
// propagate the character count to its
// parents too
charCount.back()+=cnt;

}else{
if(s[i] != ' ') charCount.back()++;
}
}

for(auto [tag,cnt]:totalCharCount){
if(cnt) {
cout<<tag<<": "<<cnt<<endl;
}
}
}
```
</details>

0 comments on commit 49c3a73

Please sign in to comment.