instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a formatter to wrap the text at a given number of characters, while maintaining the original formatting and line breaks. The formatter should also handle special characters, punctuation marks, and mixed case sentences properly. Additionally, the formatter should implement a word-wrapping algorithm that considers ... | codefeedback |
Write a function to select the second largest unique prime number in an array. The array may contain duplicates.
Example:
Input: [2, 5, 4, 7, 11, 7, 5]
Output: 5
Note: In the given example, the second largest unique prime number in the array is 5. | codefeedback |
Check if two sentences are an anagram of each other. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. For example, "Clint Eastwood" and "Old West Action" are anagrams of each other.
Given two sentences, sentence1 and sentence2, write a function to determine if they are anagr... | codefeedback |
Compress a given string to shorter characters by replacing substrings of length 4. The compressed string must also include the count of each substring occurrence.
string = "aaabbbccc"
Example Output:
compressed_string = "aaab3cc3" | codefeedback |
Convert a binary string to a decimal integer, but without using any built-in conversion functions or libraries. You can only use basic arithmetic operations (such as addition, subtraction, multiplication, and division) and loops. The binary string can have up to 1 billion digits. The time complexity should be O(n), whe... | codefeedback |
Write a function that takes in a sentence as input and returns a new sentence with the following modifications:
- The order of all words should be reversed.
- Words containing the letter 'a' or 'e' should be excluded.
- The function should also ignore any words that are shorter than 3 characters.
- The sentence may con... | codefeedback |
Write a function that computes the factorial of a positive integer. The function should be implemented using recursion.
Constraints:
- The input integer will be between 1 and 10.
- The function should have a time complexity of O(n), where n is the input integer.
- The function should also handle negative integers as i... | codefeedback |
Implement a modified Huffman algorithm to compress and decompress the following string.
"abacabadabacaba"
In the modified Huffman algorithm, characters are assigned variable length codes in such a way that no code is a prefix of another code. | codefeedback |
You are given a string. Remove duplicated characters from the string and return the output. The output should be sorted in ascending order based on the ASCII values of the characters.
For example, if the input string is "Mississippi", the output should be "Mips". | codefeedback |
Create a SQL query to select customers who have spent more than $1000 in the last month, but also exclude any customers who have made more than 5 transactions in the last week. Additionally, the query should only include customers who have made at least 2 transactions in the last month and have an average transaction a... | codefeedback |
Write a function in Python that takes in a set of integers and a subset of integers, and returns all the subsets of the given set that must contain at least one element from the specific subset of integers. The function should return the subsets in lexicographical order.
For example, given the set {1, 2, 3, 4} and the... | codefeedback |
Create a function that converts a string of words into a dictionary with the words as keys and the number of occurrences of each word as values. The function should ignore punctuation and be case-insensitive.
The function should also handle special characters, such as accented characters, and correctly count them as s... | codefeedback |
You must refactor a code to reduce the complexity and improve its readability.
The original code checks whether a given number is a prime number or not by recursively calling two functions `is_prime` and `is_composite`.
Your task is to refactor the code by creating a single function `is_prime_number` that takes an int... | codefeedback |
Given an array with n numbers, write a function to find if there exists three distinct elements in the array whose sum is equal to a given number. The array may contain duplicate numbers, but the three elements selected for the sum must be different.
For example, given the array [5, 3, 1, 8] and the number 14, the fun... | codefeedback |
Create a function to remove all duplicated words from an input sentence, while also ensuring that the order of the words remains unchanged. The function should only consider words that have at least 4 letters and are not proper nouns. The input sentence may contain punctuation and capitalization, which should be ignore... | codefeedback |
You must reverse a given array of numbers in-place without using any built-in methods or additional data structures. The time complexity should be less than O(n^2). | codefeedback |
Create a function that finds the longest palindrome substring in an input string, and returns the length of the substring.
#Example#
Input: "babad"
Output: 3
#Note#
- A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward.
- The function should return the le... | codefeedback |
Write a line of code in C# to find the index of the first occurrence of a given element in a given array, without using any built-in functions or libraries. The array may contain duplicate elements and can have a maximum length of 1000. The element is a positive integer less than or equal to 1000.
Additionally, handle... | codefeedback |
Given a string in Python, how do you extract all the unique words while preserving their order of occurrence? You are not allowed to use any built-in functions or libraries for this task. | codefeedback |
Perform insertion sort on a given array of objects. Each object has the following properties: 'name' (a string), 'age' (an integer), and 'score' (a floating-point number).
arr = [
{'name': 'John', 'age': 25, 'score': 78.5},
{'name': 'Alice', 'age': 30, 'score': 82.1},
{'name': 'Bob', 'age': 22, 'score': 76... | codefeedback |
You need to find the total length of all words in a given array of strings and return the word with the maximum length. However, you should now implement this without using any built-in functions or methods that directly solve the problem.
arr = ["abc", "def", "ghij"] | codefeedback |
Write a Python program to create a dictionary with values being squared for every key. Additionally, each key-value pair should be added to a list of tuples, sorted in descending order based on the squared values.
Example:
Input:
{'a': 2, 'b': 3, 'c': 4, 'd': 5}
Output:
{'a': 4, 'b': 9, 'c': 16, 'd': 25}
[('d', 25), ... | codefeedback |
There is an array of integer numbers. You need to replace all the odd numbers with the sum of their adjacent even numbers. If there are no adjacent even numbers, replace the odd number with the product of its adjacent even numbers. If there are no adjacent even numbers or adjacent even numbers have a sum of 0, replace ... | codefeedback |
Given a list of string objects, write an SQL query to concatenate all the strings into a single string, remove any punctuation marks, and count the number of unique vowels in the resulting string. | codefeedback |
Write an HTML form with a select drop-down that displays a range of numbers from 1 to 100,000. Additionally, the drop-down options should be dynamically populated from an API call to retrieve the numbers. The form should also have a submit button that triggers a JavaScript function to display the selected number in a s... | codefeedback |
Write a CSS page to center align a given paragraph element and add a background color to it. The paragraph element must have a minimum width of 300 pixels and a maximum width of 500 pixels. Additionally, the background color must be a gradient that transitions from a light blue (#87CEEB) to a dark blue (#00008B) from t... | codefeedback |
Write an AngularJS controller to set the "page" variable to be the same as the page parameter passed in the URL, but only if the page parameter is a positive integer greater than 10 and less than 100. Additionally, the controller should validate that the page parameter is provided in the URL and display an error messag... | codefeedback |
Write a JavaScript function to modify a given list and convert all elements to lowercase. The function should not use any built-in JavaScript methods or libraries for string manipulation. Additionally, the function should only use a constant amount of extra space (i.e. no additional data structures). The time complexit... | codefeedback |
Write a sliding window algorithm in JavaScript to collect all the subarrays with size k from an array of size n. In the resulting subarray, each element should be raised to the power of 3. Return the product of all the subarrays.
let input = [1, 2, 3, 4, 5, 6, 7, 8];
let K = 3;
Example:
Input: input = [1, 2, 3, 4, 5,... | codefeedback |
Write a Java program to find the largest prime number among a list of numbers entered by the user. The program should take input until the user enters a negative number.
Additional Requirements:
1. The program should handle inputs up to 10^6 numbers.
2. The program should be able to find the largest prime number withi... | codefeedback |
Given an array of numbers, write a prototype JavaScript function to find the average value of all numbers in the array.
If the array is empty, the function should return 0. If the array contains any non-numeric values or negative numbers, the function should skip those values and calculate the average based on the rem... | codefeedback |
Create a webpage using HTML and CSS that displays the text "Welcome to my website!" in the center of the page. The webpage should have a fixed width of 800 pixels and a height of 600 pixels. The text should be displayed in a bold and italic font with a font size of 48 pixels. Additionally, the webpage should have a bac... | codefeedback |
Sort the given array of numbers from least to greatest. The sorted array should also have the even numbers before the odd numbers. Additionally, you are not allowed to use any built-in sorting functions or libraries.
You are also not allowed to use any additional data structures such as arrays, lists, or dictionaries.... | codefeedback |
Write an SQL query to select all records from a table named "users" where the email address field contains "@gmail.com" and the first name field is not null. Additionally, sort the results in descending order based on the length of the last name field, and limit the output to only the first 10 records. | codefeedback |
Using lambda expressions, write a function to convert a given temperature value in celsius to fahrenheit. However, the input temperature may be a list of values. In this case, the function should return a list of corresponding Fahrenheit temperatures. Additionally, the function should ignore any temperature values that... | codefeedback |
Create a list comprehension expression to generate a list of the squares of all even numbers from 1 to 10, but exclude any numbers that are divisible by 3. Additionally, the final list should be sorted in descending order and only include unique elements. | codefeedback |
Write a C++ program to apply a Caesar cipher to a given string with a more complex encryption algorithm.
The Caesar cipher is a substitution cipher where each letter in the plaintext is shifted a certain number of positions down the alphabet. For this modified Caesar cipher, the shift value should now be a combination... | codefeedback |
Divide a given list of numbers by a given number and return the quotient and remainder for each number. The list can contain both positive and negative numbers.
List: [15, -20, 25, -30]
Number: 5
Note: Ensure that the quotient is rounded towards negative infinity for negative numbers. | codefeedback |
Rewrite the following Bash program to print only prime numbers between 100 and 1000.
#!/bin/sh
for i in $(seq 100 1000)
do
prime=true
for j in $(seq 2 $(($i - 1)))
do
if [ $(($i % $j)) -eq 0 ]
then
prime=false
break
fi
done
if $prime
then
echo $i
fi
done | codefeedback |
Create a program that searches a given string for a word and prints out its position. However, you are not allowed to use any built-in string search or matching functions. Instead, you need to implement your own algorithm to find the word.
String: "I am a programmer and a problem solver"
Word: "programmer"
Time compl... | codefeedback |
Create a bash script that prints a given string twenty times, but this time, the string should be stored in an array and passed as an argument to a recursive function that prints the string. Additionally, the recursive function should only be allowed to call itself a maximum of five times. | codefeedback |
Given a singly linked list, insert a given value at a specified position. The position is specified as the index (starting from 0) where the value should be inserted. The time complexity of your solution should be O(1). | codefeedback |
Create a PHP program to find the maximum of three numbers without using if...else or a comparison operator. Additionally, the program should only use a maximum of three lines of code. | codefeedback |
Explain the concept of serverside rendering in web development, highlighting its advantages and disadvantages. Discuss the importance of server-side rendering in relation to search engine optimization (SEO) and the impact it can have on website performance. Additionally, provide a detailed code example showcasing how s... | codefeedback |
Find the area of a rectangle given its width and height. However, instead of directly multiplying the width and height to find the area, you need to calculate it using a function that requires more logical steps.
First, ask the user to input the width and height of the rectangle.
Then, check if the input values are va... | codefeedback |
Please parse the given HTML string into a readable JSON object while adding the following additional requirements:
1. The function should handle self-closing HTML tags (e.g., `<img>`).
2. The function should handle inline styles and include them in the JSON object.
3. The function should handle comments in the HTML an... | codefeedback |
Edit the following code so that it prints the sum of all even elements of the given array.
arr = [1,5,8,4,2]
def sumArray(arr):
sum = 0
for i in range(len(arr)):
if arr[i] % 2 == 0:
sum += arr[i]
print(sum) | codefeedback |
Create an assembly language program to find the sum of two floating-point numbers and round the result to the nearest whole number. Additionally, the program should only use a maximum of 10 registers and should not exceed a total of 50 lines of code. | codefeedback |
Compile the following PHP code and explain the output.
```php
$a = 5;
$b = '5';
var_dump($a === $b);
```
Explain the output and provide a detailed explanation of the difference between the `==` and `===` operators in PHP. Additionally, provide examples that demonstrate the behavior of these operators when used with ... | codefeedback |
Write a routine to reverse the elements in a doubly linked list, where each node has a reference to the previous and next node. The routine should reverse the elements in place and return the new head of the reversed list.
The time complexity of your solution should be O(n), where n is the number of nodes in the list.... | codefeedback |
Create a function that sorts a given list of strings alphabetically, but with the following additional conditions:
1. Ignore case sensitivity when sorting the strings. For example, "apple" should come before "Banana".
2. If two strings have the same letters but different cases, the one with lowercase letters should co... | codefeedback |
Calculate the probability of an event that occurs exactly 3 times out of a sequence of 10 independent and identically distributed Bernoulli trials, where the probability of success for each trial is 0.3. Additionally, you are required to implement the solution using a recursive algorithm. | codefeedback |
Create a copy of an existing array, but with the elements sorted in descending order. The array can only be sorted using a recursive sorting algorithm. Your solution should have a time complexity of O(nlogn). my_arr = [5, 2, 9, 1, 7] | codefeedback |
Output the top 5 most common strings that contain at least one uppercase letter and one lowercase letter in a given list of strings. | codefeedback |
Find the closest match in a given string using the Levenshtein edit distance. If there are multiple closest matches, return the one that appears first in the original string. If there are no matches with an edit distance of 2, return an empty string.
String: algorithm
Closest match: logarism | codefeedback |
Convert the given numerical value from base 10 to base 7 using bitwise operators only.
Number: 75 | codefeedback |
Implement a search algorithm to find an element in an array with the following additional constraints:
1. The array is sorted in ascending order.
2. The array may contain duplicate elements.
3. The search algorithm should return the index of the first occurrence of the element in the array.
4. If the element is not fou... | codefeedback |
Reverse the order of elements in an array without using any built-in functions or creating a new array. The solution should have a time complexity of O(n) and should not use any extra space beyond a few integer variables. The array will contain integers ranging from -10^9 to 10^9. | codefeedback |
Calculate the area of a triangle given the lengths of its three sides. However, the sides are represented as floating-point numbers and can have decimal values. Additionally, you are not allowed to use the Heron's formula for calculating the area. Instead, you must use the Law of Cosines to find one of the angles of th... | codefeedback |
Create a function to generate random English sentences that must contain at least one word with 15 or more characters and must also satisfy the following constraints:
1. The sentence must contain at least three words.
2. The sentence must start with a capital letter and end with a period.
3. The sentence must not excee... | codefeedback |
Using a nested for loop, print out a countdown from 100 to 1, but only display odd numbers that are also prime. | codefeedback |
Interpret the following regular expression:
((\d{2})\s[A-Z]{3})|((\d{2})\s[a-z]{3})|(\d{2}) | codefeedback |
Create a program which takes an integer input n (1 <= n <= 20) and prints its factorial. The program should be able to handle large input values efficiently.
Additionally, the program should calculate the sum of all the digits in the factorial and print it. The program should also calculate the product of all the digi... | codefeedback |
Define a function that takes an array of strings and combines the strings into a single string, but only includes strings that contain both uppercase and lowercase letters. Additionally, the combined string should be sorted in descending order based on the length of each string. The function should also ignore any stri... | codefeedback |
Create a function that takes two strings as an input, removes any leading or trailing white spaces from both strings, and concatenates the two strings. If either string is empty after removing the white spaces, return an error message stating that the input strings cannot be empty. Additionally, the function should che... | codefeedback |
Write an algorithm to print out the prime numbers between 100 and 200 in an increasing order, using a recursive approach.
#Explanation#
1. Create a function called `isPrime` that takes an integer `n` as input and returns a boolean value indicating whether `n` is prime.
2. Inside the `isPrime` function, check if `n` is... | codefeedback |
Using the random module, generate a random sequence of 10 numbers from the range 1 to 20, with no repeated numbers. Additionally, ensure that the sum of the generated numbers is divisible by 3. | codefeedback |
Calculate the square root of a positive number without using any built-in function. The output should be rounded to the nearest integer.
Additional constraint: The algorithm should have a time complexity of O(log(log n)).
num = 25 | codefeedback |
Given a list of words, sort them in descending order using a bubble sort algorithm. The length of each word in the list will not exceed 50 characters. Additionally, you need to handle words that contain special characters such as punctuation marks or numbers. These special characters should be considered as part of the... | codefeedback |
Find the latitude and longitude of an input address, using only primitive data types and without using any external libraries or APIs.
However, the input address can now be a list of addresses instead of just a single address. You need to find the latitude and longitude of each address in the list.
The input will be ... | codefeedback |
Generate a random string of length n containing only lowercase letters. The string must have at least one vowel, one consonant, and one special character (!, @, #, $, %, ^, &, *, -, +, =). | codefeedback |
Aggregate and calculate the mean of the following array by grouping them by the key 'region' and excluding any scores below 7. Additionally, return the top 5 regions with the highest mean score. array = [ {'name': 'John', 'region': 'West', 'score': 6}, {'name': 'Jane', 'region': 'West', 'score': 10}, {'name': 'Bob', 'r... | codefeedback |
Create a function that takes two numerical parameters and checks if they are equal. However, you are not allowed to use any comparison operators (e.g., ==, !=, <, >) or built-in functions (e.g., equals(), compareTo()) to compare the values. Additionally, you are not allowed to use any arithmetic operators (e.g., +, -, ... | codefeedback |
Write a function to extract the substring between two given indices of a string. If the start index is greater than the end index, swap the indices and return the substring. If either index is out of range (less than 0 or greater than the length of the string), return an empty string. If both indices are out of range, ... | codefeedback |
Calculate the determinant of this matrix, where the matrix is guaranteed to be a square matrix of size n x n, where n is a positive integer.
[[2, 1, 3],
[0, 2, -1],
[1, 4, 2]] | codefeedback |
Create a class for a Counter object that will keep track of a total count, and increase and decrease the count when functions are called. Additionally, implement a feature that allows the Counter object to keep track of the count for multiple instances of the class. Each instance should have its own independent count. ... | codefeedback |
Develop a program to count the number of prime numbers in a given list, where each item is a positive integer between 1 and 100. The program should also calculate the product of all the prime numbers in the list. The list can contain up to 1000 items. Print both the count and the product of the prime numbers as the out... | codefeedback |
Generate a program to filter a list of numbers, passing only the numbers that are greater than a given number and divisible by a specific prime number, and store them in a new list. The program should also remove any duplicates from the resulting list.
Example:
Input: [12, 24, 36, 45], 36, 2
Output: [24]
Time complex... | codefeedback |
Write a SQL query to get the products with the lowest price in each category, excluding products that are out of stock. Also, include the average rating of each product in the result set. | codefeedback |
Using the SQL language, write a query to calculate the average population of cities in each country, but exclude any cities that have a population less than 1 million. Additionally, include only countries with at least 5 cities in the calculation. | codefeedback |
Using the PHP programming language, write a function to check if a string contains all vowels (a, e, i, o, u) in any order and any number of occurrences, and at least one consonant. The function should ignore case sensitivity and return true if the string meets the requirement, otherwise return false. | codefeedback |
Choose a suitable data structure for finding the minimum and maximum element from a collection of numbers, with a time complexity of O(log n), but without using any built-in data structures or libraries such as arrays, lists, or heaps. | codefeedback |
Convert the given JavaScript object to an array while excluding the properties that start with the letter 's', the properties whose values are less than 10, and the properties whose values are greater than 100. | codefeedback |
Using the Java programming language, print out the direct children of a given element in an HTML document. However, you are not allowed to use any built-in HTML parsing libraries, regular expressions, or third-party libraries. Additionally, you must implement your own algorithm for parsing and navigating the HTML docum... | codefeedback |
Write a function in Python to print out the top k most common words in a given text, where k is a positive integer input to the function. The function should ignore punctuation, consider words in a case-insensitive manner, and exclude common stop words such as "the", "and", "in", etc. If multiple words have the same fr... | codefeedback |
Write an algorithm to find the common elements in two arrays. The algorithm should have a time complexity of O(n), where n is the size of the larger array. Additionally, you are not allowed to use any additional data structures, built-in functions, or loops (such as for, while, or do-while) for solving the problem. | codefeedback |
Write a function in Java to calculate the number of days in a given month and year. Your function should handle leap years correctly and account for the differences in number of days in different months (e.g. February has 28 or 29 days depending on the year).
Additionally, implement error handling in your code to hand... | codefeedback |
Convert the given string to an all lowercase string. However, you are not allowed to use any built-in string manipulation functions or methods such as `toLowerCase()`, `lower()`, or any similar ones. You should implement your own algorithm to achieve the conversion. Additionally, your algorithm should have a time compl... | codefeedback |
Create an object to store name, age, and gender. Implement a method to calculate and store the year of birth based on the current year and age. The name should be limited to a maximum of 20 characters. Additionally, the program should validate that the age is between 1 and 120 and the gender is either male or female. | codefeedback |
Write a function to convert a given list of strings into a dictionary where the key is a string in the list, and the value is the frequency of the string in the list. Additionally, the function should ignore case sensitivity when counting the frequency. The function should have a time complexity of O(n), where n is the... | codefeedback |
Reverse the following array using slicing. Your solution should have a time complexity of O(n) and should not use any built-in functions or libraries that directly reverse the array. Additionally, your solution should handle arrays with duplicates efficiently, without using any additional space. | codefeedback |
Find the absolute difference between the objects in the following JavaScript code, considering only the values of the numeric properties and excluding any non-numeric properties. The solution should also handle nested objects and arrays, where the absolute difference should be calculated recursively. Additionally, the ... | codefeedback |
Create an algorithm for sorting a list of numbers using bubble sort. The list may contain duplicate numbers and the algorithm should ensure that the final sorted list has all duplicates grouped together.
Reference Erroneous Code:
```python
def bubble_sort(nums):
n = len(nums)
for i in range(n-1):
for j... | codefeedback |
Implement a recursive function to compute the factorial of a given number. The function should have a time complexity of O(n), where n is the given number. The function should not use any loops or iteration, and should only use recursion to calculate the factorial. Additionally, the function should handle edge cases su... | codefeedback |
Edit the existing JavaScript code to make it pass Eslint. Additionally, optimize the code to use a more efficient approach. You may not use any conditional statements or loops in the optimized code.
```
// Original Code
var arr = [1, 2, 3, 4, 5];
var sum = 0;
for (var i = 0; i < arr.length; i++) {
sum += arr[i];
}... | codefeedback |
Write a SQL query to get the sum of sales for each country, but exclude any countries that have a population greater than 100 million. Additionally, include the average sales per person for each country in the result. Ensure that the average sales per person is rounded to two decimal places. | codefeedback |
Please implement a function called `print_primes` that takes in two parameters: `start` and `end`, representing the range of numbers to check. The function should print out all the prime numbers within that range.
A prime number is a number greater than 1 that is divisible only by 1 and itself.
Your solution should h... | codefeedback |
Write a code that takes an array of integers and returns an array of all elements in the original array except for the duplicates. The code should have a time complexity of O(n), where n is the length of the array. Additionally, the code should not use any built-in functions or libraries to achieve this task. | codefeedback |
Write a code that takes a list of strings and a string, and returns a list containing all strings from the given list that have the given string as a substring. If the substring appears multiple times in a string, it should only be counted as one occurrence. The search for substrings should be case-sensitive.
Input:
-... | codefeedback |
Implement a hash table data structure from scratch in the programming language of your choice. Your implementation should include the following operations:
1. Insert(key, value): Insert a key-value pair into the hash table. If the key already exists, update its corresponding value.
2. Get(key): Retrieve the value asso... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.