<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>number of subsequences in a array divisible by n - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/number-of-subsequences-in-a-array-divisible-by-n/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/number-of-subsequences-in-a-array-divisible-by-n/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Mon, 13 Sep 2021 12:22:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>number of subsequences in a array divisible by n - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/number-of-subsequences-in-a-array-divisible-by-n/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Finding all substrings of a given number that are divisible by 11</title>
		<link>https://www.wikitechy.com/interview-questions/cpp/finding-all-substrings-of-a-given-number-that-are-divisible-by-11/</link>
					<comments>https://www.wikitechy.com/interview-questions/cpp/finding-all-substrings-of-a-given-number-that-are-divisible-by-11/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Mon, 12 Jul 2021 23:25:00 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></category>
		<category><![CDATA[Applied Materials interview questions and answers]]></category>
		<category><![CDATA[array maximum sum divisible by n in c]]></category>
		<category><![CDATA[Atos interview questions and answers]]></category>
		<category><![CDATA[BMC Software interview questions and answers]]></category>
		<category><![CDATA[Bosch India Software interview questions and answers]]></category>
		<category><![CDATA[c++ int to string]]></category>
		<category><![CDATA[c++ string]]></category>
		<category><![CDATA[c++ string contains charfind position of character in string c++]]></category>
		<category><![CDATA[c++ string length]]></category>
		<category><![CDATA[c++ string nposfind substring in char array c++]]></category>
		<category><![CDATA[c++ string to int]]></category>
		<category><![CDATA[c++ substring]]></category>
		<category><![CDATA[c++ substring before character]]></category>
		<category><![CDATA[c++ substring from end]]></category>
		<category><![CDATA[c++ substring from index to end]]></category>
		<category><![CDATA[CASTING NETWORKS INDIA PVT LIMITED interview questions and answers]]></category>
		<category><![CDATA[Chetu interview questions and answers]]></category>
		<category><![CDATA[Ciena Corporation interview questions and answers]]></category>
		<category><![CDATA[consecutive subsequences whose sum is divisible by k.]]></category>
		<category><![CDATA[continuous subarray sum multiple of k]]></category>
		<category><![CDATA[count subarrays with sum k]]></category>
		<category><![CDATA[declare string in c++]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[eInfochips interview questions and answers]]></category>
		<category><![CDATA[Electronics Arts Inc interview questions and answers]]></category>
		<category><![CDATA[find all occurrences of a substring in a string c++]]></category>
		<category><![CDATA[find character in string c++]]></category>
		<category><![CDATA[find occurrence of character in string c++]]></category>
		<category><![CDATA[find substring in string c++]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[function of library]]></category>
		<category><![CDATA[Harman International interview questions and answers]]></category>
		<category><![CDATA[how to divide a string into substrings in c++]]></category>
		<category><![CDATA[how to find a letter in a string c++]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[Larsen & Toubro interview questions and answers]]></category>
		<category><![CDATA[MagicBricks Interview Questions and Answers]]></category>
		<category><![CDATA[Mathworks India Private Limited interview questions and answers]]></category>
		<category><![CDATA[Mavenir interview questions and answers]]></category>
		<category><![CDATA[Mphasis interview questions and answers]]></category>
		<category><![CDATA[NetApp interview questions and answers]]></category>
		<category><![CDATA[number of subsequences divisible by n]]></category>
		<category><![CDATA[number of subsequences in a array divisible by n]]></category>
		<category><![CDATA[number of subsequences in a string]]></category>
		<category><![CDATA[number of subsequences in a string divisible by n]]></category>
		<category><![CDATA[number of subsequences whose sum is divisible by n]]></category>
		<category><![CDATA[number of times a string occurs as a subsequence]]></category>
		<category><![CDATA[Oracle Corporation interview questions and answers]]></category>
		<category><![CDATA[PeopleStrong interview questions and answers]]></category>
		<category><![CDATA[Philips Software Centre Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[print string in c++]]></category>
		<category><![CDATA[program to find substring in a string in c++]]></category>
		<category><![CDATA[reverse substring c++]]></category>
		<category><![CDATA[sort substring c++]]></category>
		<category><![CDATA[SRM Technologies interview questions and answers]]></category>
		<category><![CDATA[string functions in c++]]></category>
		<category><![CDATA[string in c++ programming]]></category>
		<category><![CDATA[string length in c++]]></category>
		<category><![CDATA[string match c++]]></category>
		<category><![CDATA[string programs in c++]]></category>
		<category><![CDATA[string to int c++]]></category>
		<category><![CDATA[strings in c]]></category>
		<category><![CDATA[subsequence sum divisible by k]]></category>
		<category><![CDATA[subset with sum divisible by m]]></category>
		<category><![CDATA[substr c++]]></category>
		<category><![CDATA[substr in c]]></category>
		<category><![CDATA[substring c++]]></category>
		<category><![CDATA[Symphony Teleca interview questions and answers]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[Tecnotree interview questions and answers]]></category>
		<category><![CDATA[what is string in c++]]></category>
		<category><![CDATA[Wipro Infotech interview questions and answers]]></category>
		<category><![CDATA[Wipro interview questions and answers]]></category>
		<category><![CDATA[Yash Technologies interview questions and answers]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=400</guid>

					<description><![CDATA[Answer : Query(l, r) : find if the sub-string between the indices l and r....
]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="finding-all-substrings-of-a-given-number-that-are-divisible-by-11" class="color-pink" style="text-align: justify;">Finding all substrings of a given number that are divisible by 11</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<p>To find easy to way of Divisibility by 11,</p>
<ul>
<li>The multiples of 11: 22, 33, 44, 55, etc. But we did&#8217;t easy to find the number 2728, 54695 is divisible by 11.</li>
<li>Here an easy way to test for divisibility by 11. Take the alternating sum of the digits in the number, read from left to right. If that is divisible by 11, so is the original number.</li>
<li>So, for example, 2728 has alternating sum of digits 2-7+2-8 = -11. Since -11 is divisible by 11, so is 2728.</li>
<li>Similarly, for 54695, the alternating sum of digits is 5-4+6-9+5 = 3. This is not divisible by 11, so neither is 54695.</li>
</ul>
<div class="TextHeading">
<div class="hddn">
<h2 id="given-a-large-number-n-having-number-digits-up-to-106-and-various-queries-of-the-below-form" class="color-purple">Given a large number, n (having number digits up to 10^6) and various queries of the below form :</h2>
</div>
</div>
<div class="Content">
<div class="hddn">
<ul>
<li>Query(l, r) : find if the <a href="https://www.wikitechy.com/technology/longest-even-length-substring-sum-first-second-half/" target="_blank" rel="noopener">sub-string</a> between the indices l and r (Both inclusive) are divisible by 11.</li>
</ul>
</div>
</div>
<div class="TextHeading">
<div class="hddn">
<h2 id="input" class="color-green">Input</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">n = 122164154695<br/>Queries: l = 0 r = 3, l = 1 r = 2, l = 5 r = 9, l = 0 r = 11</code></pre> </div>
<div class="TextHeading">
<div class="hddn">
<h2 id="output" class="color-green">Output</h2>
</div>
</div>
<div class="Output">
<div class="hddn">
<figure class="highlight"><div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">True<br/>True<br/>False<br/>True</code></pre> </div>
<div class="TextHeading">
<div class="hddn">
<h2 id="explanation" class="color-red">Explanation</h2>
</div>
</div>
<div class="Content">
<div class="hddn">
<ul>
<li>In the first query, 1221 is divisible by 11.</li>
<li>In the second query, 22 is divisible by 11 and so on.</li>
<li>We know that any number is divisible by 11 if the difference between sum of odd indexed digits and the sum of even indexed digits is divisible by 11, i.e.,</li>
</ul>
</div>
</div>
<div class="TextHeading">
<div class="hddn">
<h4 id="sumdigits-at-odd-places-sumdigits-at-even-places-should-be-divisible-by-11" class="color-blue">Sum(digits at odd places) &#8211; Sum(digits at even places) should be divisible by 11.</h4>
<h2 id="sample-code" class="color-red">Sample code</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">#include &lt;iostream&gt; <br/>using namespace std; <br/>  <br/>const int MAX = 1000005; <br/>  <br/>// To store sums of even and odd digits <br/>struct OddEvenSums <br/>{ <br/>    int e_sum; // Sum of even placed digits <br/>  <br/>    int o_sum; // Sum of odd placed digits <br/>}; <br/>  <br/>OddEvenSums sum[MAX]; // Auxiliary array <br/>  <br/>// Utility function to evaluate a character&#039;s <br/>// integer value <br/>int toInt(char x) <br/>{ <br/>    return int(x) - 48; <br/>} <br/>  <br/>// This function receives the string representation <br/>// of the number and precomputes the sum array <br/>void preCompute(string x) <br/>{  <br/>    sum[0].e_sum = sum[0].o_sum = 0; // Initialize everb <br/>  <br/>    // Add the respective digits depending on whether <br/>    // they&#039;re even indexed or odd indexed <br/>    for (int i=0; i&lt;x.length(); i++) <br/>    { <br/>        if (i%2==0) <br/>        { <br/>            sum[i+1].e_sum = sum[i].e_sum+toInt(x[i]); <br/>            sum[i+1].o_sum = sum[i].o_sum; <br/>        } <br/>        else<br/>        { <br/>            sum[i+1].o_sum = sum[i].o_sum+toInt(x[i]); <br/>            sum[i+1].e_sum = sum[i].e_sum; <br/>        } <br/>    } <br/>} <br/>  <br/>// This function receives l and r representing <br/>// the indices and prints the required output <br/>bool query(int l,int r) <br/>{ <br/>    int diff = (sum[r+1].e_sum - sum[r+1].o_sum) - (sum[l].e_sum - sum[l].o_sum); <br/>  <br/>    return (diff%11==0); <br/>} <br/>  <br/>//driver function to check the program <br/>int main() <br/>{ <br/>    string s = &quot;122164154695&quot;; <br/>  <br/>    preCompute(s); <br/>  <br/>    cout &lt;&lt; query(0, 3) &lt;&lt; endl; <br/>    cout &lt;&lt; query(1, 2) &lt;&lt; endl; <br/>    cout &lt;&lt; query(5, 9) &lt;&lt; endl; <br/>    cout &lt;&lt; query(0, 11) &lt;&lt; endl; <br/>  <br/>    return 0; <br/>} </code></pre> </div>
<div class="TextHeading">
<div class="hddn">
<h2 id="output-2" class="color-red">Output</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-markup code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-markup code-embed-code">1 <br/>1<br/>0<br/>1</code></pre> </div>
</div>
</div>
</div>
</div>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/cpp/finding-all-substrings-of-a-given-number-that-are-divisible-by-11/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
